Update location design

This commit is contained in:
GaidamakUA 2015-10-21 16:10:40 +03:00
parent 4ab74214d1
commit 5a18d73e44
7 changed files with 283 additions and 231 deletions

View file

@ -7,8 +7,12 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/osmo_header_dark"
android:orientation="vertical"
android:padding="8dp"
android:paddingBottom="@dimen/list_header_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingTop="@dimen/list_header_padding"
tools:showIn="@layout/local_index_fragment_header">
<LinearLayout

View file

@ -1,80 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/expandable_list_item_background"
android:minHeight="@dimen/list_item_height"
android:orientation="horizontal"
android:paddingLeft="@dimen/list_content_padding">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/expandable_list_item_background"
android:descendantFocusability="blocksDescendants"
android:minHeight="@dimen/list_item_height"
android:orientation="horizontal"
android:paddingLeft="@dimen/list_content_padding">
<CheckBox
android:id="@+id/check_local_index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:visibility="gone"
android:layout_marginRight="@dimen/local_index_check_right_margin"
android:layout_marginTop="@dimen/favorites_icon_top_margin"/>
<CheckBox
android:id="@+id/check_local_index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/local_index_check_right_margin"
android:layout_marginTop="@dimen/favorites_icon_top_margin"
android:focusable="false"
android:visibility="gone"/>
<ImageView
android:id="@+id/icon"
android:src="@drawable/ic_gpx_track"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/favorites_icon_right_margin"
android:layout_marginTop="@dimen/favorites_icon_top_margin"
android:focusable="false"/>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/favorites_icon_right_margin"
android:layout_marginTop="@dimen/favorites_icon_top_margin"
android:focusable="false"
android:src="@drawable/ic_gpx_track"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/local_index_name"
android:textSize="@dimen/default_list_text_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
tools:text="@string/app_version"/>
<TextView
android:id="@+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="Bangladesh"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/local_index_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="7dp"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"
tools:text="@string/app_version"/>
<TextView
android:id="@+id/descriptionTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="7dp"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"
tools:text="12.34 Mb * 10/4/2015"/>
<TextView
android:id="@+id/local_index_descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"
tools:text="@string/app_mode_aircraft"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="@+id/options"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:background="?attr/dashboard_button"
android:focusable="false"
android:src="@drawable/ic_overflow_menu_white"/>
<ImageButton
android:id="@+id/options"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:background="?attr/dashboard_button"
android:focusable="false"
android:src="@drawable/ic_overflow_menu_white"/>
</LinearLayout>

View file

@ -1,25 +1,5 @@
package net.osmand.plus.download;
import java.io.File;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.ui.ActiveDownloadsDialogFragment;
import net.osmand.plus.download.ui.DownloadResourceGroupFragment;
import net.osmand.plus.download.ui.LocalIndexesFragment;
import net.osmand.plus.download.ui.UpdatesIndexFragment;
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
@ -37,7 +17,31 @@ import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.ui.ActiveDownloadsDialogFragment;
import net.osmand.plus.download.ui.DownloadResourceGroupFragment;
import net.osmand.plus.download.ui.LocalIndexesFragment;
import net.osmand.plus.download.ui.UpdatesIndexFragment;
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import java.io.File;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class DownloadActivity extends BaseDownloadActivity {
public static final int UPDATES_TAB_NUMBER = 2;
public static final int LOCAL_TAB_NUMBER = 1;
public static final int DOWNLOAD_TAB_NUMBER = 0;
private List<LocalIndexInfo> localIndexInfos = new ArrayList<>();
List<TabActivity.TabItem> mTabs = new ArrayList<TabActivity.TabItem>();
@ -49,8 +53,10 @@ public class DownloadActivity extends BaseDownloadActivity {
public static final String DOWNLOAD_TAB = "download";
public static final String UPDATES_TAB = "updates";
public static final MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
public static final MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
private BannerAndDownloadFreeVersion visibleBanner;
private ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -60,7 +66,7 @@ public class DownloadActivity extends BaseDownloadActivity {
if (!indexes.isDownloadedFromInternet) {
getDownloadThread().runReloadIndexFiles();
}
setContentView(R.layout.download);
final View downloadProgressLayout = findViewById(R.id.downloadProgressLayout);
downloadProgressLayout.setVisibility(View.VISIBLE);
@ -69,13 +75,12 @@ public class DownloadActivity extends BaseDownloadActivity {
String tab = getIntent() == null || getIntent().getExtras() == null ? null : getIntent().getExtras().getString(TAB_TO_OPEN);
if (tab != null) {
if (tab.equals(DOWNLOAD_TAB)) {
currentTab = 1;
currentTab = DOWNLOAD_TAB_NUMBER;
} else if (tab.equals(UPDATES_TAB)) {
currentTab = 2;
currentTab = UPDATES_TAB_NUMBER;
}
}
visibleBanner = new BannerAndDownloadFreeVersion(findViewById(R.id.mainLayout), this);
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager = (ViewPager) findViewById(R.id.pager);
PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs);
@ -90,6 +95,27 @@ public class DownloadActivity extends BaseDownloadActivity {
mSlidingTabLayout.setViewPager(viewPager);
viewPager.setCurrentItem(currentTab);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {
}
@Override
public void onPageSelected(int i) {
if (i == UPDATES_TAB_NUMBER) {
visibleBanner.hideDownloadProgressLayout();
} else {
visibleBanner.showDownloadProgressLayout();
}
}
@Override
public void onPageScrollStateChanged(int i) {
}
});
visibleBanner = new BannerAndDownloadFreeVersion(findViewById(R.id.mainLayout), this);
final Intent intent = getIntent();
// FIXME INITIAL FILTER & INITIAL KEY
@ -99,7 +125,6 @@ public class DownloadActivity extends BaseDownloadActivity {
}
}
@Override
protected void onResume() {
super.onResume();
@ -133,7 +158,7 @@ public class DownloadActivity extends BaseDownloadActivity {
super.onPause();
getMyApplication().getAppCustomization().pauseActivity(DownloadActivity.class);
}
@Override
@UiThread
public void downloadHasFinished() {
@ -145,7 +170,7 @@ public class DownloadActivity extends BaseDownloadActivity {
}
}
}
@Override
@UiThread
public void downloadInProgress() {
@ -159,7 +184,6 @@ public class DownloadActivity extends BaseDownloadActivity {
}
@Override
@UiThread
public void newDownloadIndexes() {
@ -172,9 +196,10 @@ public class DownloadActivity extends BaseDownloadActivity {
}
downloadHasFinished();
}
private int getCurrentTab() {
return viewPager.getCurrentItem();
}
public boolean isLightActionBar() {
return ((OsmandApplication) getApplication()).getSettings().isLightActionBar();
@ -188,17 +213,22 @@ public class DownloadActivity extends BaseDownloadActivity {
private final View freeVersionDescriptionTextView;
private final View buttonsLinearLayout;
private final View freeVersionTitle;
private final OsmandSettings settings;
private ToggleCollapseFreeVersionBanner(View freeVersionDescriptionTextView,
View buttonsLinearLayout, View freeVersionTitle) {
View buttonsLinearLayout, View freeVersionTitle,
OsmandSettings settings) {
this.freeVersionDescriptionTextView = freeVersionDescriptionTextView;
this.buttonsLinearLayout = buttonsLinearLayout;
this.freeVersionTitle = freeVersionTitle;
this.settings = settings;
}
@Override
public void onClick(View v) {
if (freeVersionDescriptionTextView.getVisibility() == View.VISIBLE) {
if (freeVersionDescriptionTextView.getVisibility() == View.VISIBLE
&& isDownlodingPermitted(settings)) {
freeVersionDescriptionTextView.setVisibility(View.GONE);
buttonsLinearLayout.setVisibility(View.GONE);
} else {
@ -209,6 +239,12 @@ public class DownloadActivity extends BaseDownloadActivity {
}
}
public static boolean isDownlodingPermitted(OsmandSettings settings) {
final Integer mapsDownloaded = settings.NUMBER_OF_FREE_DOWNLOADS.get();
int downloadsLeft = BaseDownloadActivity.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - mapsDownloaded;
return Math.max(downloadsLeft, 0) > 0;
}
public static class BannerAndDownloadFreeVersion {
private final View freeVersionBanner;
private final View downloadProgressLayout;
@ -248,8 +284,12 @@ public class DownloadActivity extends BaseDownloadActivity {
initFreeVersionBanner();
updateFreeVersionBanner();
updateBannerInProgress();
if (ctx.getCurrentTab() != UPDATES_TAB_NUMBER) {
downloadProgressLayout.setVisibility(View.VISIBLE);
}
}
public void updateBannerInProgress() {
BasicProgressAsyncTask<?, ?, ?, ?> basicProgressAsyncTask = ctx.getDownloadThread().getCurrentRunningTask();
final boolean isFinished = basicProgressAsyncTask == null
@ -257,13 +297,18 @@ public class DownloadActivity extends BaseDownloadActivity {
if (isFinished) {
downloadProgressLayout.setOnClickListener(null);
updateDescriptionTextWithSize(ctx, downloadProgressLayout);
if (ctx.getCurrentTab() == UPDATES_TAB_NUMBER) {
downloadProgressLayout.setVisibility(View.GONE);
}
updateFreeVersionBanner();
} else {
boolean indeterminate = basicProgressAsyncTask.isIndeterminate();
String message = basicProgressAsyncTask.getDescription();
int percent = basicProgressAsyncTask.getProgressPercentage();
setMinimizedFreeVersionBanner(true);
updateAvailableDownloads();
downloadProgressLayout.setVisibility(View.VISIBLE);
downloadProgressLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -273,6 +318,7 @@ public class DownloadActivity extends BaseDownloadActivity {
progressBar.setIndeterminate(indeterminate);
if (indeterminate) {
leftTextView.setText(message);
rightTextView.setText(null);
} else {
progressBar.setProgress(percent);
// final String format = ctx.getString(R.string.downloading_number_of_files);
@ -280,7 +326,14 @@ public class DownloadActivity extends BaseDownloadActivity {
rightTextView.setText(percent + "%");
}
}
}
public void hideDownloadProgressLayout() {
downloadProgressLayout.setVisibility(View.GONE);
}
public void showDownloadProgressLayout() {
downloadProgressLayout.setVisibility(View.VISIBLE);
}
private void initFreeVersionBanner() {
@ -305,7 +358,7 @@ public class DownloadActivity extends BaseDownloadActivity {
}
});
laterButton.setOnClickListener(new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
buttonsLinearLayout, freeVersionBannerTitle));
buttonsLinearLayout, freeVersionBannerTitle, application.getSettings()));
}
private void updateFreeVersionBanner() {
@ -323,7 +376,7 @@ public class DownloadActivity extends BaseDownloadActivity {
}
downloadsLeftTextView.setText(ctx.getString(R.string.downloads_left_template, downloadsLeft));
freeVersionBanner.setOnClickListener(new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
buttonsLinearLayout, freeVersionBannerTitle));
buttonsLinearLayout, freeVersionBannerTitle, settings));
}
private void updateAvailableDownloads() {
@ -334,7 +387,7 @@ public class DownloadActivity extends BaseDownloadActivity {
}
private void setMinimizedFreeVersionBanner(boolean minimize) {
if (minimize) {
if (minimize && isDownlodingPermitted(application.getSettings())) {
freeVersionDescriptionTextView.setVisibility(View.GONE);
buttonsLinearLayout.setVisibility(View.GONE);
freeVersionBannerTitle.setVisibility(View.GONE);
@ -348,7 +401,7 @@ public class DownloadActivity extends BaseDownloadActivity {
@SuppressWarnings("deprecation")
public static void updateDescriptionTextWithSize(DownloadActivity activity, View view){
public static void updateDescriptionTextWithSize(DownloadActivity activity, View view) {
TextView descriptionText = (TextView) view.findViewById(R.id.rightTextView);
TextView messageTextView = (TextView) view.findViewById(R.id.leftTextView);
ProgressBar sizeProgress = (ProgressBar) view.findViewById(R.id.progressBar);
@ -356,9 +409,9 @@ public class DownloadActivity extends BaseDownloadActivity {
File dir = activity.getMyApplication().getAppPath("").getParentFile();
String size = formatGb.format(new Object[]{0});
int percent = 0;
if(dir.canRead()){
if (dir.canRead()) {
StatFs fs = new StatFs(dir.getAbsolutePath());
size = formatGb.format(new Object[]{(float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30) });
size = formatGb.format(new Object[]{(float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30)});
percent = 100 - (int) (fs.getAvailableBlocks() * 100 / fs.getBlockCount());
}
sizeProgress.setIndeterminate(false);
@ -369,5 +422,5 @@ public class DownloadActivity extends BaseDownloadActivity {
messageTextView.setText(R.string.device_memory);
}
}

View file

@ -347,8 +347,8 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
group != null && group.getType() == DownloadResourceGroupType.REGION_MAPS) {
viewHolder.setShowTypeInName(true);
viewHolder.setShowTypeInDesc(false);
} else if(group != null && (group.getType() == DownloadResourceGroupType.SRTM_HEADER ||
group.getType() == DownloadResourceGroupType.HILLSHADE_HEADER)) {
} else if(group != null && (group.getType() == DownloadResourceGroupType.SRTM_HEADER
|| group.getType() == DownloadResourceGroupType.HILLSHADE_HEADER)) {
viewHolder.setShowTypeInName(false);
viewHolder.setShowTypeInDesc(false);
} else {

View file

@ -343,6 +343,4 @@ public class ItemViewHolder {
private Drawable getContentIcon(DownloadActivity context, int resourceId, int color) {
return context.getMyApplication().getIconsCache().getPaintedContentIcon(resourceId, color);
}
}

View file

@ -3,7 +3,6 @@ package net.osmand.plus.download.ui;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.content.res.TypedArray;
@ -35,8 +34,10 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
@ -60,22 +61,23 @@ import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdate;
import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdateList;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.io.File;
import java.text.Collator;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents {
private static final Log LOG = PlatformUtil.getLog(LocalIndexesFragment.class);
private LoadLocalIndexTask asyncLoader;
private LocalIndexesAdapter listAdapter;
private AsyncTask<LocalIndexInfo, ?, ?> operationTask;
@ -87,7 +89,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
protected static int BACKUP_OPERATION = 2;
protected static int RESTORE_OPERATION = 3;
MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
private ContextMenuAdapter optionsMenuAdapter;
private ActionMode actionMode;
@ -102,7 +103,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list);
listAdapter = new LocalIndexesAdapter(getActivity());
listAdapter = new LocalIndexesAdapter(getDownloadActivity());
listView.setAdapter(listAdapter);
expandAllGroups();
setListView(listView);
@ -163,9 +164,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
asyncLoader = new LoadLocalIndexTask();
asyncLoader.execute(getActivity());
}
private void showContextMenu(final LocalIndexInfo info) {
Builder builder = new AlertDialog.Builder(getActivity());
@ -278,7 +276,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
}
}
public class LoadLocalIndexTask extends AsyncTask<Activity, LocalIndexInfo, List<LocalIndexInfo>> {
@ -453,23 +450,23 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
}
}
}
@Override
public void newDownloadIndexes() {
}
@Override
public void downloadHasFinished() {
reloadData();
}
@Override
public void downloadInProgress() {
}
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
LOG.debug("onChildClick()");
LocalIndexInfo child = listAdapter.getChild(groupPosition, childPosition);
if (!selectionMode) {
openPopUpMenu(v, child);
@ -773,9 +770,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
int warningColor;
int okColor;
int corruptedColor;
Context ctx;
DownloadActivity ctx;
public LocalIndexesAdapter(Context ctx) {
public LocalIndexesAdapter(DownloadActivity ctx) {
this.ctx = ctx;
warningColor = ctx.getResources().getColor(R.color.color_warning);
okColor = ctx.getResources().getColor(R.color.color_ok);
@ -827,7 +824,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
}
}
}
listAdapter.notifyDataSetChanged();
notifyDataSetChanged();
}
public void move(LocalIndexInfo[] values, boolean oldBackupState) {
@ -841,7 +838,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
data.get(c).add(i);
}
}
listAdapter.notifyDataSetChanged();
notifyDataSetChanged();
expandAllGroups();
}
@ -910,109 +907,27 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
}
@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = convertView;
final LocalIndexInfo child = getChild(groupPosition, childPosition);
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(net.osmand.plus.R.layout.local_index_list_item, parent, false);
}
TextView viewName = ((TextView) v.findViewById(R.id.local_index_name));
ImageButton options = (ImageButton) v.findViewById(R.id.options);
options.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_overflow_menu_white));
options.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openPopUpMenu(v, child);
}
});
ImageView icon = (ImageView) v.findViewById(R.id.icon);
if (child.isBackupedData()) {
icon.setImageDrawable(backup);
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
LocalIndexInfoViewHolder viewHolder;
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(ctx);
convertView = inflater.inflate(net.osmand.plus.R.layout.local_index_list_item, parent, false);
viewHolder = new LocalIndexInfoViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
icon.setImageDrawable(sdcard);
viewHolder = (LocalIndexInfoViewHolder) convertView.getTag();
}
viewName.setText(getNameToDisplay(child));
if (child.isNotSupported()) {
viewName.setTextColor(warningColor);
} else if (child.isCorrupted()) {
viewName.setTextColor(corruptedColor);
} else if (child.isLoaded()) {
// users confused okColor here with "uptodate", so let's leave white (black in dark app theme) as "isLoaded"
//viewName.setTextColor(okColor);
}
if (child.isBackupedData()) {
viewName.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
} else {
viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
}
TextView sizeText = (TextView) v.findViewById(R.id.local_index_size);
if (child.getSize() >= 0) {
String size;
if (child.getSize() > 100) {
size = formatMb.format(new Object[]{(float) child.getSize() / (1 << 10)});
} else {
size = child.getSize() + " kB";
}
sizeText.setText(size);
sizeText.setVisibility(View.VISIBLE);
} else {
sizeText.setVisibility(View.GONE);
}
TextView descr = ((TextView) v.findViewById(R.id.local_index_descr));
if (child.getType() == LocalIndexType.TILES_DATA) {
descr.setText(R.string.online_map);
} else {
descr.setVisibility(View.VISIBLE);
descr.setText(child.getDescription());
}
final CheckBox checkbox = (CheckBox) v.findViewById(R.id.check_local_index);
checkbox.setVisibility(selectionMode ? View.VISIBLE : View.GONE);
if (selectionMode) {
icon.setVisibility(View.GONE);
options.setVisibility(View.GONE);
checkbox.setChecked(selectedItems.contains(child));
checkbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkbox.isChecked()) {
selectedItems.add(child);
} else {
selectedItems.remove(child);
}
}
});
} else {
options.setVisibility(View.VISIBLE);
icon.setVisibility(View.VISIBLE);
}
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onChildClick(null, v, groupPosition, childPosition, 0);
}
});
return v;
viewHolder.bindLocalIndexInfo(getChild(groupPosition, childPosition));
return convertView;
}
private String getNameToDisplay(LocalIndexInfo child) {
String mapDescr = getMapDescription(child.getFileName());
String mapName = FileNameTranslationHelper.getFileName(ctx,
((OsmandApplication) getDownloadActivity().getApplication()).getResourceManager().getOsmandRegions(),
ctx.getMyApplication().getResourceManager().getOsmandRegions(),
child.getFileName());
if (mapDescr.length() > 0) {
return mapName + " - " + mapDescr;
} else {
return mapName;
}
return mapName;
}
@Override
@ -1023,12 +938,12 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
LayoutInflater inflater = LayoutInflater.from(ctx);
v = inflater.inflate(R.layout.download_item_list_section, parent, false);
}
StringBuilder name = new StringBuilder(group.getType().getHumanString(getDownloadActivity()));
StringBuilder name = new StringBuilder(group.getType().getHumanString(ctx));
if (group.getSubfolder() != null) {
name.append(" ").append(group.getSubfolder());
}
if (group.isBackupedData()) {
name.append(" - ").append(getString(R.string.local_indexes_cat_backup));
name.append(" - ").append(ctx.getString(R.string.local_indexes_cat_backup));
}
TextView nameView = ((TextView) v.findViewById(R.id.section_name));
TextView sizeView = ((TextView) v.findViewById(R.id.section_description));
@ -1048,7 +963,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
if (size > 1 << 20) {
sz = DownloadActivity.formatGb.format(new Object[]{(float) size / (1 << 20)});
} else {
sz = formatMb.format(new Object[]{(float) size / (1 << 10)});
sz = DownloadActivity.formatMb.format(new Object[]{(float) size / (1 << 10)});
}
}
@ -1057,7 +972,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
nameView.setText(name.toString());
v.setOnClickListener(null);
TypedValue typedValue = new TypedValue();
Resources.Theme theme = ctx.getTheme();
theme.resolveAttribute(R.attr.ctx_menu_info_view_bg, typedValue, true);
@ -1103,6 +1018,98 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
}
return "";
}
private class LocalIndexInfoViewHolder {
private final TextView nameTextView;
private final ImageButton options;
private final ImageView icon;
private final TextView descriptionTextView;
private final CheckBox checkbox;
public LocalIndexInfoViewHolder(View view) {
nameTextView = ((TextView) view.findViewById(R.id.nameTextView));
options = (ImageButton) view.findViewById(R.id.options);
icon = (ImageView) view.findViewById(R.id.icon);
descriptionTextView = (TextView) view.findViewById(R.id.descriptionTextView);
checkbox = (CheckBox) view.findViewById(R.id.check_local_index);
}
public void bindLocalIndexInfo(final LocalIndexInfo child) {
options.setImageDrawable(ctx.getMyApplication().getIconsCache()
.getContentIcon(R.drawable.ic_overflow_menu_white));
options.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openPopUpMenu(v, child);
}
});
if (child.isBackupedData()) {
icon.setImageDrawable(backup);
} else {
icon.setImageDrawable(sdcard);
}
nameTextView.setText(getNameToDisplay(child));
if (child.isNotSupported()) {
nameTextView.setTextColor(warningColor);
} else if (child.isCorrupted()) {
nameTextView.setTextColor(corruptedColor);
} else if (child.isLoaded()) {
// users confused okColor here with "uptodate", so let's leave white (black in dark app theme) as "isLoaded"
//nameTextView.setTextColor(okColor);
}
if (child.isBackupedData()) {
nameTextView.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
} else {
nameTextView.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
}
StringBuilder builder = new StringBuilder();
if (child.getSize() >= 0) {
if (child.getSize() > 100) {
builder.append(DownloadActivity.formatMb.format(new Object[]{(float) child.getSize() / (1 << 10)}));
} else {
builder.append(child.getSize()).append(" kB");
}
builder.append("");
}
final String mapDescription = getMapDescription(child.getFileName());
if (mapDescription.length() > 0) {
builder.append(mapDescription).append("");
}
if (child.getType() == LocalIndexType.TILES_DATA) {
builder.append(ctx.getString(R.string.online_map));
} else {
builder.append(child.getDescription());
}
descriptionTextView.setText(builder.toString());
checkbox.setVisibility(selectionMode ? View.VISIBLE : View.GONE);
if (selectionMode) {
icon.setVisibility(View.GONE);
options.setVisibility(View.GONE);
checkbox.setChecked(selectedItems.contains(child));
checkbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkbox.isChecked()) {
selectedItems.add(child);
} else {
selectedItems.remove(child);
}
}
});
} else {
options.setVisibility(View.VISIBLE);
icon.setVisibility(View.VISIBLE);
}
}
}
}
private void openPopUpMenu(View v, final LocalIndexInfo info) {
@ -1187,7 +1194,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
IndexItem ii = new IndexItem(iu.fileName, "Incremental update", iu.timestamp, iu.sizeText,
iu.contentSize, iu.containerSize, DownloadActivityType.LIVE_UPDATES_FILE);
is[i++] = ii;
}
getDownloadActivity().startDownload(is);
}

View file

@ -1360,5 +1360,4 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
v.findViewById(R.id.check_item).setVisibility(View.GONE);
}
}