Merge pull request #978 from Bars107/master

Fixed merge bugs. Added loading indicators.
This commit is contained in:
vshcherb 2014-11-28 14:51:26 +01:00
commit 0f60457d30
5 changed files with 80 additions and 29 deletions

View file

@ -3,6 +3,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_fav"
android:background="@drawable/bg_cardui"
android:layout_marginBottom="4dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

View file

@ -17,13 +17,24 @@
style="@style/DashboardGeneralButton"/>
</LinearLayout>
<net.osmand.plus.views.OsmAndMapSurfaceView
android:id="@+id/MapView"
android:layout_width="fill_parent"
android:layout_height="110dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="2dp"
android:contentDescription="@string/map_view"
android:visibility="gone"/>
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<ProgressBar android:id="@+id/map_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="@android:style/Widget.ProgressBar.Small"
android:indeterminate="true"
android:indeterminateOnly="true"/>
<net.osmand.plus.views.OsmAndMapSurfaceView
android:id="@+id/MapView"
android:layout_width="fill_parent"
android:layout_height="110dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="2dp"
android:contentDescription="@string/map_view"
android:visibility="gone"/>
</RelativeLayout>
</LinearLayout>

View file

@ -20,9 +20,17 @@
android:textSize="14sp"
android:textColor="@color/dashboard_black"/>
<TextView android:id="@+id/update_count"
android:layout_marginLeft="2dp"
android:layout_width="wrap_content"
android:textColor="@color/dashboard_blue"
android:layout_height="wrap_content"/>
<ProgressBar android:id="@+id/main_progress"
android:visibility="visible"
android:layout_marginLeft="2dp"
android:indeterminate="true"
android:indeterminateOnly="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<View android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"/>

View file

@ -2,16 +2,20 @@ package net.osmand.plus.activities;
import java.io.File;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;
import android.support.v4.app.Fragment;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.dashboard.DashFavoritesFragment;
import net.osmand.plus.dashboard.DashMapFragment;
import net.osmand.plus.dashboard.DashPluginsFragment;
@ -19,6 +23,7 @@ import net.osmand.plus.dashboard.DashSearchFragment;
import net.osmand.plus.dashboard.DashUpdatesFragment;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.sherpafy.TourViewActivity;
import android.app.Activity;
@ -382,7 +387,7 @@ public class DashboardActivity extends BaseDownloadActivity {
menu.add(0, 1, 0, R.string.settings).setIcon(R.drawable.ic_ac_settings)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, 2, 0, R.string.exit_Button).setIcon(R.drawable.ic_ac_close)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
return true;
}
@ -460,4 +465,29 @@ public class DashboardActivity extends BaseDownloadActivity {
textVersionView.setText(content);
textVersionView.setMovementMethod(LinkMovementMethod.getInstance());
}
@Override
public void updateProgress(boolean updateOnlyProgress) {
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = BaseDownloadActivity.downloadListIndexThread.getCurrentRunningTask();
for(WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof DashUpdatesFragment) {
if(!f.isDetached()) {
((DashUpdatesFragment) f).updateProgress(basicProgressAsyncTask, updateOnlyProgress);
}
}
}
}
@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);
}
}
}
}
}

View file

@ -57,11 +57,11 @@ public class DashUpdatesFragment extends DashBaseFragment {
@Override
public void onResume() {
super.onResume();
if (BaseDownloadActivity.downloadListIndexThread != null){
if (BaseDownloadActivity.downloadListIndexThread != null) {
currentProgress = null;
cancelButton = null;
updatedDownloadsList(BaseDownloadActivity.downloadListIndexThread.getItemsToUpdate());
}
updatedDownloadsList(BaseDownloadActivity.downloadListIndexThread.getItemsToUpdate());
}
public void updatedDownloadsList(List<IndexItem> list) {
@ -73,15 +73,12 @@ public class DashUpdatesFragment extends DashBaseFragment {
progressBars.clear();
baseNames.clear();
downloadButtons.clear();
if (list.size() > 0) {
mainView.setVisibility(View.VISIBLE);
} else {
mainView.setVisibility(View.GONE);
mainView.findViewById(R.id.main_progress).setVisibility(View.GONE);
((TextView) mainView.findViewById(R.id.update_count)).setText(String.valueOf(list.size()));
if (list.size() < 1) {
return;
}
((TextView)mainView.findViewById(R.id.update_count)).setText(String.valueOf(list.size()));
LinearLayout updates = (LinearLayout) mainView.findViewById(R.id.updates_items);
updates.removeAllViews();
@ -104,10 +101,10 @@ public class DashUpdatesFragment extends DashBaseFragment {
public void onClick(View view) {
getDownloadActivity().startDownload(item);
currentProgress = progressBar;
cancelButton = (ImageButton)view;
cancelButton = (ImageButton) view;
}
});
downloadButtons.add((ImageButton)downloadButton);
downloadButtons.add((ImageButton) downloadButton);
baseNames.add(item.getBasename());
progressBars.add(progressBar);
updates.addView(view);
@ -115,24 +112,24 @@ public class DashUpdatesFragment extends DashBaseFragment {
updateProgress(BaseDownloadActivity.downloadListIndexThread.getCurrentRunningTask(), false);
}
private BaseDownloadActivity getDownloadActivity(){
return (BaseDownloadActivity)getActivity();
private BaseDownloadActivity getDownloadActivity() {
return (BaseDownloadActivity) getActivity();
}
public void updateProgress(BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask, boolean updateOnlyProgress) {
if (basicProgressAsyncTask == null){
if (basicProgressAsyncTask == null) {
return;
}
//needed when rotation is performed and progress can be null
if (currentProgress == null){
if (currentProgress == null) {
getProgressIfPossible(basicProgressAsyncTask.getDescription());
if (currentProgress == null){
if (currentProgress == null) {
return;
}
}
if(updateOnlyProgress){
if(!basicProgressAsyncTask.isIndeterminate()){
if (updateOnlyProgress) {
if (!basicProgressAsyncTask.isIndeterminate()) {
currentProgress.setProgress(basicProgressAsyncTask.getProgressPercentage());
}
} else {
@ -150,6 +147,7 @@ public class DashUpdatesFragment extends DashBaseFragment {
});
boolean intermediate = basicProgressAsyncTask.isIndeterminate();
currentProgress.setVisibility(intermediate ? View.GONE : View.VISIBLE);
//getView().findViewById(R.id.main_progress).setVisibility(intermediate ? View.VISIBLE : View.GONE);
if (!intermediate) {
currentProgress.setProgress(basicProgressAsyncTask.getProgressPercentage());
}
@ -157,8 +155,11 @@ public class DashUpdatesFragment extends DashBaseFragment {
}
private void getProgressIfPossible(String message) {
for (int i =0; i<baseNames.size(); i++){
if (message.equals(getActivity().getString(R.string.downloading_file_new) + " " + baseNames.get(i))){
if (getActivity() == null){
return;
}
for (int i = 0; i < baseNames.size(); i++) {
if (message.equals(getActivity().getString(R.string.downloading_file_new) + " " + baseNames.get(i))) {
currentProgress = progressBars.get(i);
cancelButton = downloadButtons.get(i);
currentProgress.setVisibility(View.VISIBLE);