Merge DownloadIndexesThread
This commit is contained in:
commit
424727cced
6 changed files with 87 additions and 27 deletions
29
OsmAnd/res/layout/update_index_frament.xml
Normal file
29
OsmAnd/res/layout/update_index_frament.xml
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginLeft="0dp"
|
||||
android:layout_marginRight="0dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<net.osmand.plus.widgets.ButtonEx
|
||||
android:id="@+id/updateAllButton"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"
|
||||
android:background="?attr/downloadButtonBackground"
|
||||
android:text="@string/update_all"
|
||||
osmand:textAllCapsCompat="true"
|
||||
tools:visibility="visible"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -2018,4 +2018,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
|
|||
<string name="confirm_download_roadmaps">Are you sure you want to download map of roads, even though you have full map?</string>
|
||||
<string name="value_downloaded_from_max">%1$.1f from %2$.1f MB</string>
|
||||
<string name="file_size_in_mb">%.1f MB</string>
|
||||
<string name="update_all">Update all(%1$s Mb)</string>
|
||||
</resources>
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.widget.Toast;
|
||||
|
@ -76,10 +77,12 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
|||
}
|
||||
|
||||
|
||||
@UiThread
|
||||
public void updateDownloadList(List<IndexItem> list) {
|
||||
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public void updateProgress(boolean updateOnlyProgress, Object tag) {
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.os.AsyncTask;
|
|||
import android.os.AsyncTask.Status;
|
||||
import android.os.Build;
|
||||
import android.os.StatFs;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -550,11 +551,11 @@ public class DownloadIndexesThread {
|
|||
}
|
||||
|
||||
protected void onPostExecute(DownloadIndexesResult result) {
|
||||
notifyFilesToUpdateChanged();
|
||||
indexFiles = result.indexFiles;
|
||||
resourcesByRegions = result.resourcesByRegions;
|
||||
voiceRecItems = result.voiceRecItems;
|
||||
voiceTTSItems = result.voiceTTSItems;
|
||||
|
||||
if (indexFiles != null && uiActivity != null) {
|
||||
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
|
||||
IndexItem basemap = indexFiles.getBasemap();
|
||||
|
@ -680,6 +681,7 @@ public class DownloadIndexesThread {
|
|||
@Override
|
||||
protected void onPostExecute(List<IndexItem> filtered) {
|
||||
prepareFilesToUpdate();
|
||||
notifyFilesToUpdateChanged();
|
||||
currentRunningTask.remove(this);
|
||||
if (uiActivity != null) {
|
||||
uiActivity.categorizationFinished(filtered, cats);
|
||||
|
@ -710,6 +712,13 @@ public class DownloadIndexesThread {
|
|||
itemsToUpdate.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void notifyFilesToUpdateChanged() {
|
||||
List<IndexItem> filtered = getCachedIndexFiles();
|
||||
if (filtered != null) {
|
||||
if (uiActivity != null) {
|
||||
uiActivity.updateDownloadList(itemsToUpdate);
|
||||
}
|
||||
|
|
|
@ -165,20 +165,20 @@ public class IndexItem implements Comparable<IndexItem>, HasName, Parcelable {
|
|||
this.initializedName = initializedName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IndexItem{" +
|
||||
"description='" + description + '\'' +
|
||||
", fileName='" + fileName + '\'' +
|
||||
", simplifiedFileName='" + simplifiedFileName + '\'' +
|
||||
", size='" + size + '\'' +
|
||||
", timestamp=" + timestamp +
|
||||
", contentSize=" + contentSize +
|
||||
", containerSize=" + containerSize +
|
||||
", type=" + type.getTag() +
|
||||
", extra=" + extra +
|
||||
'}';
|
||||
}
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// return "IndexItem{" +
|
||||
// "description='" + description + '\'' +
|
||||
// ", fileName='" + fileName + '\'' +
|
||||
// ", simplifiedFileName='" + simplifiedFileName + '\'' +
|
||||
// ", size='" + size + '\'' +
|
||||
// ", timestamp=" + timestamp +
|
||||
// ", contentSize=" + contentSize +
|
||||
// ", containerSize=" + containerSize +
|
||||
// ", type=" + type.getTag() +
|
||||
// ", extra=" + extra +
|
||||
// '}';
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
|
|
|
@ -19,12 +19,15 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmAndListFragment;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -33,11 +36,8 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Denis
|
||||
* on 09.09.2014.
|
||||
*/
|
||||
public class UpdatesIndexFragment extends OsmAndListFragment {
|
||||
private static final Log LOG = PlatformUtil.getLog(UpdateIndexAdapter.class);
|
||||
private UpdateIndexAdapter listAdapter;
|
||||
List<IndexItem> indexItems = new ArrayList<>();
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (BaseDownloadActivity.downloadListIndexThread != null) {
|
||||
indexItems = new ArrayList<IndexItem>(DownloadActivity.downloadListIndexThread.getItemsToUpdate());
|
||||
indexItems = new ArrayList<>(DownloadActivity.downloadListIndexThread.getItemsToUpdate());
|
||||
}
|
||||
createListView();
|
||||
setHasOptionsMenu(true);
|
||||
|
@ -53,11 +53,11 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
|
|||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.update_index, container, false);
|
||||
return inflater.inflate(R.layout.update_index_frament, container, false);
|
||||
}
|
||||
|
||||
private void createListView() {
|
||||
updateHeader();
|
||||
updateUpdateAllButton();
|
||||
if (indexItems.size() == 0) {
|
||||
if (DownloadActivity.downloadListIndexThread.isDownloadedFromInternet()) {
|
||||
indexItems.add(new IndexItem(getString(R.string.everything_up_to_date), "", 0, "", 0, 0, null));
|
||||
|
@ -77,14 +77,32 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
|
|||
setListAdapter(listAdapter);
|
||||
}
|
||||
|
||||
private void updateHeader() {
|
||||
private void updateUpdateAllButton() {
|
||||
View view = getView();
|
||||
if (getView() == null) {
|
||||
return;
|
||||
}
|
||||
String header = getActivity().getString(R.string.download_tab_updates) + " - " + indexItems.size();
|
||||
((TextView) view.findViewById(R.id.header)).
|
||||
setText(header);
|
||||
final TextView updateAllButton = (TextView) view.findViewById(R.id.updateAllButton);
|
||||
if (indexItems.size() == 0 || indexItems.get(0).getType() == null) {
|
||||
updateAllButton.setVisibility(View.GONE);
|
||||
} else {
|
||||
updateAllButton.setVisibility(View.VISIBLE);
|
||||
long downloadsSize = 0;
|
||||
for (IndexItem indexItem : indexItems) {
|
||||
downloadsSize += indexItem.getSize();
|
||||
}
|
||||
String updateAllText = getActivity().getString(R.string.update_all, downloadsSize >> 20);
|
||||
updateAllButton.setText(updateAllText);
|
||||
updateAllButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
for (IndexItem indexItem : indexItems) {
|
||||
getMyActivity().addToDownload(indexItem);
|
||||
}
|
||||
getMyActivity().downloadFilesCheckFreeVersion();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,7 +130,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
|
|||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
updateHeader();
|
||||
updateUpdateAllButton();
|
||||
ActionBar actionBar = getMyActivity().getSupportActionBar();
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
|
||||
|
||||
|
|
Loading…
Reference in a new issue