From 9f2eb7c8a21523ced16dd4b66221d4a4420a3ea0 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Thu, 21 Jan 2016 18:34:50 +0200 Subject: [PATCH] Reports loading data visual feedback --- OsmAnd/res/layout/fragment_reports.xml | 35 +++++++-- .../activities/actions/AppModeDialog.java | 21 +++--- .../plus/liveupdates/ReportsFragment.java | 75 +++++++++++++++++-- 3 files changed, 106 insertions(+), 25 deletions(-) diff --git a/OsmAnd/res/layout/fragment_reports.xml b/OsmAnd/res/layout/fragment_reports.xml index 599c5c8bed..ade55e2f58 100644 --- a/OsmAnd/res/layout/fragment_reports.xml +++ b/OsmAnd/res/layout/fragment_reports.xml @@ -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"> - + + android:layout_marginLeft="8dp" + android:layout_marginRight="56dp"/> + + + android:text="0"/> + android:text="0"/> diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java b/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java index abfc74892a..904413f28d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java @@ -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 selected, boolean showDefault, diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java index 2ab27b22ae..4a74179cb8 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java @@ -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 queryRegionNames = new HashMap<>(); ArrayList 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 onResponseListener = new GetJsonAsyncTask.OnResponseListener() { @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 onResponseListener) { + enableProgress(); GetJsonAsyncTask totalChangesByMontAsyncTask = new GetJsonAsyncTask<>(Protocol.TotalChangesByMonthResponse.class); totalChangesByMontAsyncTask.setOnResponseListener(onResponseListener); @@ -271,5 +299,38 @@ public class ReportsFragment extends BaseOsmAndFragment implements SearchSelecti protected ArrayList 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; } }