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:progressDrawable="@drawable/number_of_downloads_progress_bar_drawable"
android:saveEnabled="false"
tools:progress="5"/>
tools:progress="6"/>
<LinearLayout
android:id="@+id/marksLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
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>
android:orientation="horizontal"/>
</FrameLayout>
<LinearLayout

View file

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

View file

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