Added view for map updates

This commit is contained in:
Denis 2014-11-25 18:23:37 +02:00
parent 0a4a26be91
commit 742eb0a64a
7 changed files with 83 additions and 35 deletions

View file

@ -10,12 +10,18 @@
<LinearLayout
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="40dp">
<TextView android:text="@string/map_update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_height="fill_parent"
android:paddingTop="2dp"
android:gravity="center_vertical"
android:layout_marginLeft="15dp"
android:textSize="14sp"
android:textColor="@color/dashboard_black"/>
<TextView android:id="@+id/update_count"
android:layout_width="wrap_content"
android:textColor="@color/dashboard_blue"
android:layout_height="wrap_content"/>
<View android:layout_width="0dp"
android:layout_weight="1"

View file

@ -6,13 +6,18 @@
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_height="50dp">
<View android:layout_width="match_parent"
android:background="@color/dashboard_divider"
android:layout_height="1dp"/>
<LinearLayout android:orientation="horizontal"
android:layout_marginLeft="12dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="50dp">
<TextView android:id="@+id/map_name"
android:textColor="@color/dashboard_black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/map_descr"

View file

@ -1,5 +1,6 @@
package net.osmand.plus.dashboard;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
@ -9,6 +10,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.plus.R;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadEntry;
import net.osmand.plus.download.IndexItem;
@ -22,6 +24,14 @@ public class DashUpdatesFragment extends DashBaseFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_updates_fragment, container, false);
(view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Intent intent = new Intent(view.getContext(), getMyApplication().getAppCustomization().getDownloadIndexActivity());
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.UPDATES_TAB);
getActivity().startActivity(intent);
}
});
return view;
}
@ -30,8 +40,17 @@ public class DashUpdatesFragment extends DashBaseFragment {
super.onCreate(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
if (BaseDownloadActivity.downloadListIndexThread != null){
updatedDownloadsList(BaseDownloadActivity.downloadListIndexThread.getItemsToUpdate());
}
}
public void updatedDownloadsList(List<IndexItem> list) {
View mainView = getView();
//it may be null because download index thread is async
if (mainView == null) {
return;
}
@ -41,6 +60,9 @@ public class DashUpdatesFragment extends DashBaseFragment {
mainView.setVisibility(View.GONE);
return;
}
((TextView)mainView.findViewById(R.id.update_count)).setText(String.valueOf(list.size()));
LinearLayout updates = (LinearLayout) mainView.findViewById(R.id.updates_items);
updates.removeAllViews();
@ -51,9 +73,9 @@ public class DashUpdatesFragment extends DashBaseFragment {
}
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dash_updates_item, null, false);
String eName = item.getVisibleDescription(getMyApplication()) + "\n"
+ item.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
String d = item.getDate(getMyApplication().getResourceManager().getDateFormat()) + "\n" + item.getSizeDescription(getMyApplication());
String name = item.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions());
String d = item.getDate(getMyApplication().getResourceManager().getDateFormat()) + ", " + item.getSizeDescription(getMyApplication());
String eName = name.replace("\n", " ");
((TextView) view.findViewById(R.id.map_name)).setText(eName);
((TextView) view.findViewById(R.id.map_descr)).setText(d);
(view.findViewById(R.id.btn_download)).setOnClickListener(new View.OnClickListener() {
@ -63,6 +85,7 @@ public class DashUpdatesFragment extends DashBaseFragment {
getDownloadActivity().getEntriesToDownload().put(item, download);
}
});
updates.addView(view);
}
}

View file

@ -7,6 +7,7 @@ import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
@ -22,11 +23,10 @@ import net.osmand.plus.activities.MainMenuActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TipsAndTricksActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.*;
import net.osmand.util.MapUtils;
import java.lang.ref.WeakReference;
import java.util.*;
/**
@ -35,8 +35,6 @@ import java.util.*;
public class DashboardActivity extends BaseDownloadActivity {
public static final boolean TIPS_AND_TRICKS = false;
public static DownloadIndexesThread downloadListIndexThread;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -46,16 +44,6 @@ public class DashboardActivity extends BaseDownloadActivity {
getSupportActionBar().setBackgroundDrawable(color);
getSupportActionBar().setIcon(android.R.color.transparent);
if(downloadListIndexThread == null) {
downloadListIndexThread = new DownloadIndexesThread(this);
}
if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) {
downloadListIndexThread.runCategorization(DownloadActivityType.NORMAL_FILE);
} else {
downloadListIndexThread.runReloadIndexFiles();
}
downloadListIndexThread.setUiActivity(this);
android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = manager.beginTransaction();
@ -107,6 +95,18 @@ public class DashboardActivity extends BaseDownloadActivity {
return true;
}
@Override
public void updateDownloadList(List<IndexItem> list){
for(WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof DashUpdatesFragment) {
if(!f.isDetached()) {
((DashUpdatesFragment) f).updatedDownloadsList(list);
}
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;

View file

@ -2,13 +2,17 @@ package net.osmand.plus.download;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -20,9 +24,24 @@ public class BaseDownloadActivity extends SherlockFragmentActivity {
protected DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
protected OsmandSettings settings;
public static DownloadIndexesThread downloadListIndexThread;
protected List<WeakReference<Fragment>> fragList = new ArrayList<WeakReference<Fragment>>();
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(downloadListIndexThread == null) {
downloadListIndexThread = new DownloadIndexesThread(this);
}
if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) {
downloadListIndexThread.runCategorization(type);
} else {
downloadListIndexThread.runReloadIndexFiles();
}
downloadListIndexThread.setUiActivity(this);
}
public void updateDownloadList(List<IndexItem> list){
}
@ -129,5 +148,11 @@ public class BaseDownloadActivity extends SherlockFragmentActivity {
downloadFilesPreCheckSpace();
}
}
@Override
public void onAttachFragment(Fragment fragment) {
fragList.add(new WeakReference<Fragment>(fragment));
}
}

View file

@ -47,7 +47,6 @@ public class DownloadActivity extends BaseDownloadActivity {
private TextView progressPercent;
private ImageView cancel;
private List<LocalIndexInfo> localIndexInfos = new ArrayList<LocalIndexInfo>();
List<WeakReference<Fragment>> fragList = new ArrayList<WeakReference<Fragment>>();
private String initialFilter = "";
@ -56,6 +55,7 @@ public class DownloadActivity extends BaseDownloadActivity {
public static final String TAB_TO_OPEN = "Tab_to_open";
public static final String DOWNLOAD_TAB = "download";
public static final String UPDATES_TAB = "updates";
@Override
@ -66,15 +66,6 @@ public class DownloadActivity extends BaseDownloadActivity {
setProgressBarIndeterminateVisibility(false);
setContentView(R.layout.tab_content);
if(downloadListIndexThread == null) {
downloadListIndexThread = new DownloadIndexesThread(this);
}
if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) {
downloadListIndexThread.runCategorization(type);
} else {
downloadListIndexThread.runReloadIndexFiles();
}
downloadListIndexThread.setUiActivity(this);
settings = ((OsmandApplication) getApplication()).getSettings();
tabHost = (TabHost) findViewById(android.R.id.tabhost);
@ -145,6 +136,8 @@ public class DownloadActivity extends BaseDownloadActivity {
if (tab != null) {
if (tab.equals(DOWNLOAD_TAB)){
tabHost.setCurrentTab(1);
} else if (tab.equals(UPDATES_TAB)){
tabHost.setCurrentTab(2);
}
}
}
@ -439,10 +432,6 @@ public class DownloadActivity extends BaseDownloadActivity {
return ((OsmandApplication) getApplication()).getSettings().isLightActionBar();
}
@Override
public void onAttachFragment(Fragment fragment) {
fragList.add(new WeakReference<Fragment>(fragment));
}
private void copyFilesForAndroid19(final String newLoc) {
SettingsGeneralActivity.MoveFilesToDifferentDirectory task =

View file

@ -42,7 +42,7 @@ public class UpdatesIndexFragment extends SherlockListFragment {
updateColor = getResources().getColor(R.color.color_update);
osmandRegions = getMyApplication().getResourceManager().getOsmandRegions();
List<IndexItem> indexItems = new ArrayList<IndexItem>();
if (DownloadActivity.downloadListIndexThread != null) {
if (BaseDownloadActivity.downloadListIndexThread != null) {
indexItems = DownloadActivity.downloadListIndexThread.getItemsToUpdate();
}
listAdapter = new UpdateIndexAdapter(getDownloadActivity(), R.layout.download_index_list_item, indexItems);