Downloads bugs

This commit is contained in:
GaidamakUA 2015-11-16 16:48:09 +02:00
parent 78cc750b24
commit 22cebfba7e
4 changed files with 69 additions and 156 deletions

View file

@ -55,108 +55,13 @@
android:max="10" android:max="10"
android:progressDrawable="@drawable/number_of_downloads_progress_bar_drawable" android:progressDrawable="@drawable/number_of_downloads_progress_bar_drawable"
android:saveEnabled="false" android:saveEnabled="false"
tools:progress="5"/> tools:progress="6"/>
<LinearLayout <LinearLayout
android:id="@+id/marksLinearLayout"
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"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_black"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
</FrameLayout> </FrameLayout>
<LinearLayout <LinearLayout

View file

@ -21,7 +21,9 @@ import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Space;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -115,6 +117,8 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
} }
setContentView(R.layout.download); setContentView(R.layout.download);
//noinspection ConstantConditions
getSupportActionBar().setTitle(R.string.shared_string_map);
final View downloadProgressLayout = findViewById(R.id.downloadProgressLayout); final View downloadProgressLayout = findViewById(R.id.downloadProgressLayout);
downloadProgressLayout.setVisibility(View.VISIBLE); downloadProgressLayout.setVisibility(View.VISIBLE);
updateDescriptionTextWithSize(this, downloadProgressLayout); updateDescriptionTextWithSize(this, downloadProgressLayout);
@ -145,22 +149,6 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
mSlidingTabLayout.setViewPager(viewPager); mSlidingTabLayout.setViewPager(viewPager);
viewPager.setCurrentItem(currentTab); viewPager.setCurrentItem(currentTab);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {
}
@Override
public void onPageSelected(int i) {
visibleBanner.updateBannerInProgress();
}
@Override
public void onPageScrollStateChanged(int i) {
}
});
visibleBanner = new BannerAndDownloadFreeVersion(findViewById(R.id.mainLayout), this, true); visibleBanner = new BannerAndDownloadFreeVersion(findViewById(R.id.mainLayout), this, true);
final Intent intent = getIntent(); final Intent intent = getIntent();
@ -175,15 +163,15 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
public DownloadIndexesThread getDownloadThread() { public DownloadIndexesThread getDownloadThread() {
return downloadThread; return downloadThread;
} }
public void startDownload(IndexItem... indexItem) { public void startDownload(IndexItem... indexItem) {
downloadValidationManager.startDownload(this, indexItem); downloadValidationManager.startDownload(this, indexItem);
} }
public void makeSureUserCancelDownload(IndexItem item) { public void makeSureUserCancelDownload(IndexItem item) {
downloadValidationManager.makeSureUserCancelDownload(this, item); downloadValidationManager.makeSureUserCancelDownload(this, item);
} }
@Override @Override
public void onAttachFragment(Fragment fragment) { public void onAttachFragment(Fragment fragment) {
fragSet.add(new WeakReference<Fragment>(fragment)); fragSet.add(new WeakReference<Fragment>(fragment));
@ -218,7 +206,7 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
public List<LocalIndexInfo> getLocalIndexInfos() { public List<LocalIndexInfo> getLocalIndexInfos() {
return localIndexInfos; return localIndexInfos;
} }
public OsmandApplication getMyApplication() { public OsmandApplication getMyApplication() {
return (OsmandApplication) getApplication(); return (OsmandApplication) getApplication();
} }
@ -234,11 +222,11 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
@UiThread @UiThread
public void downloadHasFinished() { public void downloadHasFinished() {
visibleBanner.updateBannerInProgress(); visibleBanner.updateBannerInProgress();
if(downloadItem != null && downloadItem != getMyApplication().getRegions().getWorldRegion() if (downloadItem != null && downloadItem != getMyApplication().getRegions().getWorldRegion()
&& !WorldRegion.WORLD_BASEMAP.equals(downloadItem.getRegionDownloadNameLC())) { && !WorldRegion.WORLD_BASEMAP.equals(downloadItem.getRegionDownloadNameLC())) {
boolean firstMap = !getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.get(); boolean firstMap = !getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.get();
if(firstMap) { if (firstMap) {
initSettingsFirstMap(downloadItem); initSettingsFirstMap(downloadItem);
} }
showGoToMap(downloadItem); showGoToMap(downloadItem);
@ -252,8 +240,6 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
} }
} }
@Override @Override
@UiThread @UiThread
@ -268,7 +254,6 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
} }
} }
@Override @Override
@UiThread @UiThread
@ -287,10 +272,6 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
return viewPager.getCurrentItem(); return viewPager.getCurrentItem();
} }
public boolean isLightActionBar() {
return ((OsmandApplication) getApplication()).getSettings().isLightActionBar();
}
public void showDialog(FragmentActivity activity, DialogFragment fragment) { public void showDialog(FragmentActivity activity, DialogFragment fragment) {
fragment.show(activity.getSupportFragmentManager(), "dialog"); fragment.show(activity.getSupportFragmentManager(), "dialog");
} }
@ -372,7 +353,7 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
initFreeVersionBanner(); initFreeVersionBanner();
updateBannerInProgress(); updateBannerInProgress();
} }
public void updateBannerInProgress() { public void updateBannerInProgress() {
BasicProgressAsyncTask<?, ?, ?, ?> basicProgressAsyncTask = ctx.getDownloadThread().getCurrentRunningTask(); BasicProgressAsyncTask<?, ?, ?, ?> basicProgressAsyncTask = ctx.getDownloadThread().getCurrentRunningTask();
final boolean isFinished = basicProgressAsyncTask == null final boolean isFinished = basicProgressAsyncTask == null
@ -442,8 +423,33 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
} }
} }
}); });
laterButton.setOnClickListener(new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView, ToggleCollapseFreeVersionBanner clickListener =
buttonsLinearLayout, freeVersionBannerTitle, application.getSettings())); new ToggleCollapseFreeVersionBanner(freeVersionDescriptionTextView,
buttonsLinearLayout, freeVersionBannerTitle, application.getSettings());
laterButton.setOnClickListener(clickListener);
LinearLayout marksLinearLayout = (LinearLayout) freeVersionBanner.findViewById(R.id.marksLinearLayout);
Space spaceView = new Space(ctx);
LinearLayout.LayoutParams layoutParams =
new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1);
spaceView.setLayoutParams(layoutParams);
marksLinearLayout.addView(spaceView);
int markWidth = (int) (1 * ctx.getResources().getDisplayMetrics().density);
int colorBlack = ctx.getResources().getColor(R.color.color_black);
for (int i = 1; i < DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS; i++) {
View markView = new View(ctx);
layoutParams = new LinearLayout.LayoutParams(markWidth, ViewGroup.LayoutParams.MATCH_PARENT);
markView.setLayoutParams(layoutParams);
markView.setBackgroundColor(colorBlack);
marksLinearLayout.addView(markView);
spaceView = new Space(ctx);
layoutParams = new LinearLayout.LayoutParams(0,
ViewGroup.LayoutParams.MATCH_PARENT, 1);
spaceView.setLayoutParams(layoutParams);
marksLinearLayout.addView(spaceView);
}
updateFreeVersionBanner(); updateFreeVersionBanner();
} }
@ -528,10 +534,10 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
RegionParams params = reg.getParams(); RegionParams params = reg.getParams();
boolean americanSigns = "american".equals(params.getRegionRoadSigns()); boolean americanSigns = "american".equals(params.getRegionRoadSigns());
boolean leftHand = "yes".equals(params.getRegionLeftHandDriving()); boolean leftHand = "yes".equals(params.getRegionLeftHandDriving());
MetricsConstants mc = "miles".equals(params.getRegionMetric()) ? MetricsConstants mc = "miles".equals(params.getRegionMetric()) ?
MetricsConstants.MILES_AND_FOOTS : MetricsConstants.KILOMETERS_AND_METERS; MetricsConstants.MILES_AND_FOOTS : MetricsConstants.KILOMETERS_AND_METERS;
for (DrivingRegion r : DrivingRegion.values()) { for (DrivingRegion r : DrivingRegion.values()) {
if(r.americanSigns == americanSigns && r.leftHandDriving == leftHand && if (r.americanSigns == americanSigns && r.leftHandDriving == leftHand &&
r.defMetrics == mc) { r.defMetrics == mc) {
drg = r; drg = r;
break; break;
@ -557,28 +563,28 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
} }
} }
} }
public void setDownloadItem(WorldRegion region) { public void setDownloadItem(WorldRegion region) {
if(downloadItem == null) { if (downloadItem == null) {
downloadItem = region; downloadItem = region;
} else if(region == null) { } else if (region == null) {
downloadItem = null; downloadItem = null;
} }
} }
private void showGoToMap(WorldRegion region) { private void showGoToMap(WorldRegion region) {
GoToMapFragment fragment = new GoToMapFragment(); GoToMapFragment fragment = new GoToMapFragment();
fragment.regionCenter = region.getRegionCenter(); fragment.regionCenter = region.getRegionCenter();
fragment.regionName = region.getLocaleName(); fragment.regionName = region.getLocaleName();
fragment.show(getFragmentManager(), GoToMapFragment.TAG); fragment.show(getFragmentManager(), GoToMapFragment.TAG);
} }
private void showDownloadWorldMapIfNeeded() { private void showDownloadWorldMapIfNeeded() {
if(getDownloadThread().getCurrentDownloadingItem() == null) { if (getDownloadThread().getCurrentDownloadingItem() == null) {
return; return;
} }
IndexItem worldMap = getDownloadThread().getIndexes().getWorldBaseMapItem(); IndexItem worldMap = getDownloadThread().getIndexes().getWorldBaseMapItem();
if(!SUGGESTED_TO_DOWNLOAD_BASEMAP && worldMap != null && (!worldMap.isDownloaded() || worldMap.isOutdated()) && if (!SUGGESTED_TO_DOWNLOAD_BASEMAP && worldMap != null && (!worldMap.isDownloaded() || worldMap.isOutdated()) &&
!getDownloadThread().isDownloading(worldMap)) { !getDownloadThread().isDownloading(worldMap)) {
SUGGESTED_TO_DOWNLOAD_BASEMAP = true; SUGGESTED_TO_DOWNLOAD_BASEMAP = true;
AskMapDownloadFragment fragment = new AskMapDownloadFragment(); AskMapDownloadFragment fragment = new AskMapDownloadFragment();
@ -586,7 +592,7 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
fragment.show(getFragmentManager(), AskMapDownloadFragment.TAG); fragment.show(getFragmentManager(), AskMapDownloadFragment.TAG);
} }
} }
private void showFirstTimeExternalStorage() { private void showFirstTimeExternalStorage() {
final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime(this); final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime(this);
final boolean externalExists = final boolean externalExists =
@ -742,9 +748,8 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
} }
} }
public static class GoToMapFragment extends BottomSheetDialogFragment { public static class GoToMapFragment extends BottomSheetDialogFragment {
public static final String TAG = "GoToMapFragment"; public static final String TAG = "GoToMapFragment";
@ -776,7 +781,7 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
closeImageButton.setOnClickListener(new View.OnClickListener() { closeImageButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if(getActivity() instanceof DownloadActivity) { if (getActivity() instanceof DownloadActivity) {
((DownloadActivity) getActivity()).setDownloadItem(null); ((DownloadActivity) getActivity()).setDownloadItem(null);
} }
dismiss(); dismiss();
@ -803,8 +808,7 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
outState.putSerializable(KEY_GOTO_MAP_REGION_CENTER, regionCenter); outState.putSerializable(KEY_GOTO_MAP_REGION_CENTER, regionCenter);
} }
} }
} }

View file

@ -23,7 +23,7 @@ import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import java.text.MessageFormat; import java.text.MessageFormat;
public class DownloadValidationManager { public class DownloadValidationManager {
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 5; public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 7;
protected OsmandSettings settings; protected OsmandSettings settings;
private OsmandApplication app; private OsmandApplication app;
private DownloadIndexesThread downloadThread; private DownloadIndexesThread downloadThread;

View file

@ -3,7 +3,9 @@ package net.osmand.plus.download.ui;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v7.internal.view.ContextThemeWrapper;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -49,7 +51,7 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
private SearchListAdapter listAdapter; private SearchListAdapter listAdapter;
private BannerAndDownloadFreeVersion banner; private BannerAndDownloadFreeVersion banner;
private String searchText; private String searchText;
private SearchView search; private SearchView searchView;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -100,17 +102,19 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
listView.setOnItemClickListener(this); listView.setOnItemClickListener(this);
listView.setAdapter(listAdapter); listView.setAdapter(listAdapter);
search = new SearchView(getActivity()); TypedValue typedValue = new TypedValue();
getActivity().getTheme().resolveAttribute(R.attr.toolbar_theme, typedValue, true);
searchView = new SearchView(new ContextThemeWrapper(getActivity(), typedValue.data));
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 0); params.setMargins(0, 0, 0, 0);
search.setLayoutParams(params); searchView.setLayoutParams(params);
toolbar.addView(search); toolbar.addView(searchView);
search.setOnCloseListener(new SearchView.OnCloseListener() { searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override @Override
public boolean onClose() { public boolean onClose() {
if (search.getQuery().length() == 0) { if (searchView.getQuery().length() == 0) {
dismiss(); dismiss();
return true; return true;
} }
@ -118,13 +122,13 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
} }
}); });
search.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override @Override
public void onFocusChange(View v, boolean hasFocus) { public void onFocusChange(View v, boolean hasFocus) {
} }
}); });
search.setOnQueryTextListener(new SearchView.OnQueryTextListener() { searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override @Override
public boolean onQueryTextSubmit(String query) { public boolean onQueryTextSubmit(String query) {
return false; return false;
@ -181,9 +185,9 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
search.setIconified(false); searchView.setIconified(false);
if (!Algorithms.isEmpty(searchText)) { if (!Algorithms.isEmpty(searchText)) {
search.setQuery(searchText, true); searchView.setQuery(searchText, true);
} }
} }