Implemented update tab

This commit is contained in:
Denis 2014-09-11 12:35:40 +03:00
parent 8483371d06
commit cfae45eea2
5 changed files with 85 additions and 24 deletions

View file

@ -60,7 +60,7 @@ public class DownloadActivity extends SherlockFragmentActivity {
tabHost.setup();
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
mTabsAdapter = new FavouritesActivity.TabsAdapter(this, tabHost, viewPager, settings);
mTabsAdapter.addTab(tabHost.newTabSpec("LOCAL_INDEX").setIndicator("Local maps"),
mTabsAdapter.addTab(tabHost.newTabSpec("LOCAL_INDEX").setIndicator("Local"),
LocalIndexesFragment.class, null);
mTabsAdapter.addTab(tabHost.newTabSpec("DOWNLOADS").setIndicator("Downloads"),
DownloadIndexFragment.class, null);
@ -272,4 +272,9 @@ public class DownloadActivity extends SherlockFragmentActivity {
bld.setNegativeButton(R.string.default_buttons_no, null);
bld.show();
}
public void updateDownloadList(List<IndexItem> list){
Fragment fragment = mTabsAdapter.getItem(2);
((UpdatesIndexFragment) fragment).updateItemsList(list);
}
}

View file

@ -27,7 +27,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
private DownloadIndexFilter myFilter;
private final List<IndexItem> indexFiles;
private final List<IndexItemCategory> list = new ArrayList<IndexItemCategory>();
private DownloadIndexFragment downloadActivity;
private DownloadIndexFragment downloadFragment;
private Map<String, String> indexFileNames = null;
private Map<String, String> indexActivatedFileNames = null;
@ -38,7 +38,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
private java.text.DateFormat format;
public DownloadIndexAdapter(DownloadIndexFragment downloadFragment, List<IndexItem> indexFiles) {
this.downloadActivity = downloadFragment;
this.downloadFragment = downloadFragment;
this.indexFiles = new ArrayList<IndexItem>(indexFiles);
List<IndexItemCategory> cats = IndexItemCategory.categorizeIndexItems(downloadFragment.getMyApplication(), indexFiles);
synchronized (this) {
@ -61,11 +61,11 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
}
public void collapseTrees(final CharSequence constraint) {
downloadActivity.getDownloadActivity().runOnUiThread(new Runnable() {
downloadFragment.getDownloadActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
synchronized (DownloadIndexAdapter.this) {
final ExpandableListView expandableListView = downloadActivity.getExpandableListView();
final ExpandableListView expandableListView = downloadFragment.getExpandableListView();
for (int i = 0; i < getGroupCount(); i++) {
int cp = getChildrenCount(i);
if (cp < 7) {
@ -124,7 +124,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
}
}
List<IndexItem> filter = new ArrayList<IndexItem>();
Context c = downloadActivity.getDownloadActivity();
Context c = downloadFragment.getDownloadActivity();
for (IndexItem item : indexFiles) {
boolean add = true;
String indexLC = osmandRegions.getDownloadNameIndexLowercase(item.getBasename());
@ -165,11 +165,11 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
list.clear();
Collection<IndexItem> items = (Collection<IndexItem>) results.values;
if (items != null && !items.isEmpty()) {
list.addAll(IndexItemCategory.categorizeIndexItems(downloadActivity.getMyApplication(), items));
list.addAll(IndexItemCategory.categorizeIndexItems(downloadFragment.getMyApplication(), items));
} else if(DownloadIndexAdapter.this.indexFiles.isEmpty()){
list.add(new IndexItemCategory(downloadActivity.getResources().getString(R.string.no_index_file_to_download), 1));
list.add(new IndexItemCategory(downloadFragment.getResources().getString(R.string.no_index_file_to_download), 1));
} else {
list.add(new IndexItemCategory(downloadActivity.getResources().getString(R.string.select_index_file_to_download), 1));
list.add(new IndexItemCategory(downloadFragment.getResources().getString(R.string.select_index_file_to_download), 1));
}
}
notifyDataSetChanged();
@ -217,7 +217,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
View v = convertView;
IndexItemCategory group = getGroup(groupPosition);
if (v == null) {
LayoutInflater inflater = (LayoutInflater) downloadActivity.getDownloadActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
LayoutInflater inflater = (LayoutInflater) downloadFragment.getDownloadActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
v = inflater.inflate(net.osmand.plus.R.layout.expandable_list_item_category, parent, false);
}
final View row = v;
@ -232,27 +232,27 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) downloadActivity.getDownloadActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
LayoutInflater inflater = (LayoutInflater) downloadFragment.getDownloadActivity().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
v = inflater.inflate(net.osmand.plus.R.layout.download_index_list_item, parent, false);
}
final View row = v;
TextView item = (TextView) row.findViewById(R.id.download_item);
TextView description = (TextView) row.findViewById(R.id.download_descr);
IndexItem e = (IndexItem) getChild(groupPosition, childPosition);
OsmandApplication clctx = downloadActivity.getMyApplication();
OsmandApplication clctx = downloadFragment.getMyApplication();
String eName = e.getVisibleDescription(clctx) + "\n" + e.getVisibleName(clctx, osmandRegions);
item.setText(eName.trim()); //$NON-NLS-1$
String d = e.getDate(format) + "\n" + e.getSizeDescription(clctx);
description.setText(d.trim());
CheckBox ch = (CheckBox) row.findViewById(R.id.check_download_item);
ch.setChecked(downloadActivity.getDownloadActivity().getEntriesToDownload().containsKey(e));
ch.setChecked(downloadFragment.getDownloadActivity().getEntriesToDownload().containsKey(e));
ch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
ch.setChecked(!ch.isChecked());
downloadActivity.onChildClick(downloadActivity.getExpandableListView(), row, groupPosition, childPosition, getChildId(groupPosition, childPosition));
downloadFragment.onChildClick(downloadFragment.getExpandableListView(), row, groupPosition, childPosition, getChildId(groupPosition, childPosition));
}
});
@ -277,22 +277,22 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
} else if (e.getDate(format) != null) {
String sfName = e.getTargetFileName();
if (e.getDate(format).equals(indexActivatedFileNames.get(sfName))) {
item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : "
item.setText(item.getText() + "\n" + downloadFragment.getResources().getString(R.string.local_index_installed) + " : "
+ indexActivatedFileNames.get(sfName));
item.setTextColor(okColor); // GREEN
item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
} else if (e.getDate(format).equals(indexFileNames.get(sfName))) {
item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : "
item.setText(item.getText() + "\n" + downloadFragment.getResources().getString(R.string.local_index_installed) + " : "
+ indexFileNames.get(sfName));
item.setTextColor(okColor);
item.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
} else if (indexActivatedFileNames.containsKey(sfName)) {
item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : "
item.setText(item.getText() + "\n" + downloadFragment.getResources().getString(R.string.local_index_installed) + " : "
+ indexActivatedFileNames.get(sfName));
item.setTextColor(updateColor); // LIGHT_BLUE
item.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
} else {
item.setText(item.getText() + "\n" + downloadActivity.getResources().getString(R.string.local_index_installed) + " : "
item.setText(item.getText() + "\n" + downloadFragment.getResources().getString(R.string.local_index_installed) + " : "
+ indexFileNames.get(sfName));
item.setTextColor(updateColor);
item.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);

View file

@ -347,7 +347,6 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
public void updateDownloadButton(boolean scroll) {
View view = getView();
//TODO find out why view and getexpandablelistview can be null
if (view == null || getExpandableListView() == null){
return;
}

View file

@ -561,6 +561,7 @@ public class DownloadIndexesThread {
}
}
itemsToUpdate.size();
uiFragment.getDownloadActivity().updateDownloadList(itemsToUpdate);
}

View file

@ -1,8 +1,15 @@
package net.osmand.plus.download;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ExpandableListView;
import android.view.ViewGroup;
import android.widget.*;
import com.actionbarsherlock.app.SherlockListFragment;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import java.util.ArrayList;
@ -12,12 +19,17 @@ import java.util.Map;
/**
* Created by Denis on 09.09.2014.
*/
public class UpdatesIndexFragment extends OsmandExpandableListFragment {
public class UpdatesIndexFragment extends SherlockListFragment {
private OsmandRegions osmandRegions;
private java.text.DateFormat format;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
format = getMyApplication().getResourceManager().getDateFormat();
osmandRegions = getMyApplication().getResourceManager().getOsmandRegions();
setListAdapter(new UpdateIndexAdapter(getDownloadActivity(), R.layout.download_index_list_item, DownloadActivity.downloadListIndexThread.getItemsToUpdate()));
}
@Override
@ -28,11 +40,55 @@ public class UpdatesIndexFragment extends OsmandExpandableListFragment {
}
public void updateItemsList(List<IndexItem> items){
UpdateIndexAdapter adapter = (UpdateIndexAdapter) getListAdapter();
if (adapter == null){
return;
}
adapter.clear();
for (IndexItem item : items){
adapter.add(item);
}
}
@Override
public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i2, long l) {
return false;
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
}
public DownloadActivity getDownloadActivity() { return (DownloadActivity)getActivity(); }
private class UpdateIndexAdapter extends ArrayAdapter<IndexItem>{
List<IndexItem> items;
public UpdateIndexAdapter(Context context, int resource, List<IndexItem> items) {
super(context, resource, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null){
LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.download_index_list_item, null);
}
TextView name = (TextView) v.findViewById(R.id.download_item);
TextView description = (TextView) v.findViewById(R.id.download_descr);
IndexItem e = items.get(position);
String eName = e.getVisibleDescription(getMyApplication()) + "\n" + e.getVisibleName(getMyApplication(), osmandRegions);
name.setText(eName.trim()); //$NON-NLS-1$
String d = e.getDate(format) + "\n" + e.getSizeDescription(getMyApplication());
description.setText(d);
CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
ch.setChecked(getDownloadActivity().getEntriesToDownload().containsKey(e));
return v;
}
}
public OsmandApplication getMyApplication() { return getDownloadActivity().getMyApplication(); }
}