Reports loading data visual feedback

This commit is contained in:
GaidamakUA 2016-01-21 18:34:50 +02:00
parent 7d1060c926
commit 9f2eb7c8a2
3 changed files with 106 additions and 25 deletions

View file

@ -12,12 +12,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:columnCount="2"
android:paddingLeft="16dp">
android:columnCount="2">
<TextView
android:layout_height="48dp"
android:layout_columnSpan="2"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:gravity="center_vertical"
android:text="@string/select_month_and_country"
@ -31,14 +31,15 @@
<ImageView
android:id="@+id/calendarImageView"
android:layout_height="60dp"
android:layout_marginLeft="16dp"
android:src="@drawable/ic_action_data"/>
<!-- 24 is magic number + margin 16 = 42-->
<!-- 40 is magic number + margin 16 = 56-->
<Spinner
android:id="@+id/montReportsSpinner"
android:layout_gravity="fill_horizontal|fill_vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="42dp"
android:layout_marginRight="56dp"
android:gravity="center_vertical"/>
<View
@ -49,6 +50,7 @@
<ImageView
android:id="@+id/regionIconImageView"
android:layout_height="60dp"
android:layout_marginLeft="16dp"
android:src="@drawable/ic_world_globe_dark"/>
<include
@ -57,7 +59,21 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"/>
android:layout_marginLeft="8dp"
android:layout_marginRight="56dp"/>
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_height="8dp"
android:layout_columnSpan="2"
android:layout_gravity="fill_horizontal"
android:layout_marginRight="40dp"
android:padding="0dp"
android:indeterminate="true"
tools:progress="50"
tools:visibility="visible"
android:visibility="invisible"/>
<View
android:layout_height="1dp"
@ -67,6 +83,7 @@
<ImageView
android:id="@+id/numberOfContributorsIcon"
android:layout_height="60dp"
android:layout_marginLeft="16dp"
android:src="@drawable/ic_group"/>
<LinearLayout
@ -76,6 +93,7 @@
android:orientation="vertical">
<TextView
android:id="@+id/numberOfContributorsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/number_of_contributors"
@ -86,7 +104,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
tools:text="65"/>
android:text="0"/>
</LinearLayout>
<View
@ -95,9 +113,9 @@
android:background="?attr/dashboard_divider"/>
<ImageView
android:id="@+id/numberOfEditsIcon"
android:layout_height="60dp"
android:layout_marginLeft="16dp"
android:src="@drawable/ic_group"/>
<LinearLayout
@ -107,6 +125,7 @@
android:orientation="vertical">
<TextView
android:id="@+id/numberOfEditsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/number_of_edits"
@ -117,7 +136,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
tools:text="1125"/>
android:text="0"/>
</LinearLayout>
</GridLayout>

View file

@ -1,15 +1,5 @@
package net.osmand.plus.activities.actions;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
@ -18,6 +8,17 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class AppModeDialog {
public static View prepareAppModeView(Activity a, final Set<ApplicationMode> selected, boolean showDefault,

View file

@ -2,13 +2,19 @@ package net.osmand.plus.liveupdates;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.AttrRes;
import android.support.annotation.ColorInt;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
@ -49,6 +55,16 @@ public class ReportsFragment extends BaseOsmAndFragment implements SearchSelecti
HashMap<String, String> queryRegionNames = new HashMap<>();
ArrayList<String> regionNames = new ArrayList<>();
private ImageView numberOfContributorsIcon;
private ImageView numberOfEditsIcon;
private TextView numberOfContributorsTitle;
private TextView numberOfEditsTitle;
private ProgressBar progressBar;
private int inactiveColor;
private int textColorPrimary;
private int textColorSecondary;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -74,8 +90,13 @@ public class ReportsFragment extends BaseOsmAndFragment implements SearchSelecti
setThemedDrawable(view, R.id.calendarImageView, R.drawable.ic_action_data);
setThemedDrawable(view, R.id.regionIconImageView, R.drawable.ic_world_globe_dark);
setThemedDrawable(view, R.id.numberOfContributorsIcon, R.drawable.ic_group);
setThemedDrawable(view, R.id.numberOfEditsIcon, R.drawable.ic_group);
numberOfContributorsIcon = (ImageView) view.findViewById(R.id.numberOfContributorsIcon);
setThemedDrawable(numberOfContributorsIcon, R.drawable.ic_group);
numberOfEditsIcon = (ImageView) view.findViewById(R.id.numberOfEditsIcon);
setThemedDrawable(numberOfEditsIcon, R.drawable.ic_map);
numberOfContributorsTitle = (TextView) view.findViewById(R.id.numberOfContributorsTitle);
numberOfEditsTitle = (TextView) view.findViewById(R.id.numberOfEditsTitle);
progressBar = (ProgressBar) view.findViewById(R.id.progress);
contributorsTextView = (TextView) view.findViewById(R.id.contributorsTextView);
editsTextView = (TextView) view.findViewById(R.id.editsTextView);
@ -94,6 +115,11 @@ public class ReportsFragment extends BaseOsmAndFragment implements SearchSelecti
}
};
montReportsSpinner.setOnItemSelectedListener(onItemSelectedListener);
inactiveColor = getColorFromAttr(R.attr.plugin_details_install_header_bg);
textColorPrimary = getColorFromAttr(android.R.attr.textColorPrimary);
textColorSecondary = getColorFromAttr(android.R.attr.textColorSecondary);
return view;
}
@ -101,6 +127,11 @@ public class ReportsFragment extends BaseOsmAndFragment implements SearchSelecti
int monthItemPosition = montReportsSpinner.getSelectedItemPosition();
String monthUrlString = monthsForReportsAdapter.getQueryString(monthItemPosition);
String countryUrlString = queryRegionNames.get(countryNameTextView.getText().toString());
tryUpdateData(monthUrlString, countryUrlString);
}
private void tryUpdateData(String monthUrlString, String regionUrlString) {
GetJsonAsyncTask.OnResponseListener<Protocol.TotalChangesByMonthResponse> onResponseListener =
new GetJsonAsyncTask.OnResponseListener<Protocol.TotalChangesByMonthResponse>() {
@Override
@ -113,13 +144,10 @@ public class ReportsFragment extends BaseOsmAndFragment implements SearchSelecti
editsTextView.setText(String.valueOf(response.changes));
}
}
disableProgress();
}
};
requestData(monthUrlString, countryUrlString, onResponseListener);
}
private void requestData(String monthUrlString, String regionUrlString,
GetJsonAsyncTask.OnResponseListener<Protocol.TotalChangesByMonthResponse> onResponseListener) {
enableProgress();
GetJsonAsyncTask<Protocol.TotalChangesByMonthResponse> totalChangesByMontAsyncTask =
new GetJsonAsyncTask<>(Protocol.TotalChangesByMonthResponse.class);
totalChangesByMontAsyncTask.setOnResponseListener(onResponseListener);
@ -271,5 +299,38 @@ public class ReportsFragment extends BaseOsmAndFragment implements SearchSelecti
protected ArrayList<String> getList() {
return ((ReportsFragment) getParentFragment()).regionNames;
}
@Override
protected int getListItemIcon() {
return R.drawable.ic_map;
}
}
private void enableProgress() {
numberOfContributorsIcon.setImageDrawable(getPaintedContentIcon(R.drawable.ic_group, inactiveColor));
numberOfEditsIcon.setImageDrawable(getPaintedContentIcon(R.drawable.ic_map, inactiveColor));
numberOfContributorsTitle.setTextColor(inactiveColor);
numberOfEditsTitle.setTextColor(inactiveColor);
progressBar.setVisibility(View.VISIBLE);
contributorsTextView.setTextColor(inactiveColor);
editsTextView.setTextColor(inactiveColor);
}
private void disableProgress() {
numberOfContributorsIcon.setImageDrawable(getContentIcon(R.drawable.ic_group));
numberOfEditsIcon.setImageDrawable(getContentIcon(R.drawable.ic_map));
numberOfContributorsTitle.setTextColor(textColorSecondary);
numberOfEditsTitle.setTextColor(textColorSecondary);
progressBar.setVisibility(View.INVISIBLE);
contributorsTextView.setTextColor(textColorPrimary);
editsTextView.setTextColor(textColorPrimary);
}
@ColorInt
private int getColorFromAttr(@AttrRes int colorAttribute) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = getActivity().getTheme();
theme.resolveAttribute(colorAttribute, typedValue, true);
return typedValue.data;
}
}