Refactoring

This commit is contained in:
GaidamakUA 2016-01-12 17:49:42 +02:00
parent 71a84fcbc4
commit 180126c5c0
16 changed files with 92 additions and 55 deletions

View file

@ -22,24 +22,31 @@
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<ImageView
android:src="@drawable/widget_time"/>
<Spinner android:layout_gravity="fill_horizontal"/>
android:id="@+id/calendarImageView"
android:src="@drawable/ic_action_data"/>
<Spinner
android:id="@+id/montReportsSpinner"
android:layout_gravity="fill_horizontal"/>
<View
android:layout_column="1"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<ImageView
android:id="@+id/regionIconImageView"
android:src="@drawable/ic_world_globe_dark"
android:layout_rowSpan="2"/>
<TextView
android:text="Report for:"/>
<Spinner android:layout_gravity="fill_horizontal"/>
<Spinner
android:id="@+id/regionReportsSpinner"
android:layout_gravity="fill_horizontal"/>
<View
android:layout_columnSpan="2"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<ImageView
android:src="@drawable/ic_world_globe_dark"
android:id="@+id/numberOfContributorsIcon"
android:src="@drawable/ic_group"
android:layout_rowSpan="2"/>
<TextView
android:text="Number of contributors"/>
@ -51,7 +58,8 @@
android:background="?attr/dashboard_divider"/>
<ImageView
android:src="@drawable/ic_world_globe_dark"
android:id="@+id/numberOfEditsIcon"
android:src="@drawable/ic_group"
android:layout_rowSpan="2"/>
<TextView
android:text="Number of edits"/>

View file

@ -27,6 +27,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.base.OsmAndListFragment;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.util.MapUtils;

View file

@ -50,6 +50,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.base.OsmandExpandableListFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.plus.myplaces.FavoritesActivity;

View file

@ -32,8 +32,8 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.base.OsmAndListFragment;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;

View file

@ -35,8 +35,8 @@ import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.base.OsmAndListFragment;
import net.osmand.plus.poi.NominatimPoiFilter;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter;

View file

@ -37,9 +37,9 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.ActionBarProgressActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording;
import net.osmand.plus.base.OsmAndListFragment;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.myplaces.FavoritesActivity;

View file

@ -0,0 +1,42 @@
package net.osmand.plus.base;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
/**
* Created by GaidamakUA on 1/12/16.
*/
public class BaseOsmAndFragment extends Fragment {
private IconsCache iconsCache;
protected OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}
protected IconsCache getIconsCache() {
if (iconsCache == null) {
iconsCache = getMyApplication().getIconsCache();
}
return iconsCache;
}
protected Drawable getPaintedContentIcon(@DrawableRes int id, @ColorInt int color){
return getIconsCache().getPaintedContentIcon(id, color);
}
protected Drawable getContentIcon(@DrawableRes int id){
return getIconsCache().getContentIcon(id);
}
protected void setThemedDrawable(View parent, @IdRes int viewId, @DrawableRes int iconId) {
((ImageView) parent.findViewById(viewId)).setImageDrawable(getContentIcon(iconId));
}
}

View file

@ -1,11 +1,12 @@
package net.osmand.plus.activities;
package net.osmand.plus.base;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.widget.ArrayAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
public abstract class OsmAndListFragment extends ListFragment {
@Override

View file

@ -1,12 +1,9 @@
package net.osmand.plus.activities;
package net.osmand.plus.base;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.view.Menu;
import android.view.MenuItem;
@ -15,18 +12,17 @@ import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
public abstract class OsmandExpandableListFragment extends Fragment
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
public abstract class OsmandExpandableListFragment extends BaseOsmAndFragment
implements OnChildClickListener {
protected ExpandableListView listView;
protected ExpandableListAdapter adapter;
public OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}
@Override
public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, Bundle savedInstanceState) {
View v = createView(inflater, container);

View file

@ -46,7 +46,7 @@ import net.osmand.plus.activities.LocalIndexHelper;
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.base.OsmandExpandableListFragment;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;

View file

@ -19,7 +19,7 @@ import android.widget.TextView;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.base.OsmAndListFragment;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.DownloadResources;

View file

@ -51,9 +51,9 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.OsmandExpandableListFragment;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.download.ui.LocalIndexesFragment;
import net.osmand.plus.helpers.AndroidUiHelper;

View file

@ -41,9 +41,9 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.base.OsmAndListFragment;
import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.util.Algorithms;

View file

@ -6,7 +6,6 @@ import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextWatcher;
@ -28,8 +27,8 @@ import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiFilter;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -39,7 +38,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class AdvancedEditPoiFragment extends Fragment
public class AdvancedEditPoiFragment extends BaseOsmAndFragment
implements EditPoiDialogFragment.OnFragmentActivatedListener {
private static final String TAG = "AdvancedEditPoiFragment";
private static final Log LOG = PlatformUtil.getLog(AdvancedEditPoiFragment.class);
@ -68,8 +67,7 @@ public class AdvancedEditPoiFragment extends Fragment
int height = size.y;
view.findViewById(R.id.screenFiller).setMinimumHeight(height);
deleteDrawable = ((OsmandApplication) getActivity().getApplication()).getIconsCache()
.getPaintedContentIcon(R.drawable.ic_action_remove_dark,
deleteDrawable = getPaintedContentIcon(R.drawable.ic_action_remove_dark,
getActivity().getResources().getColor(R.color.dash_search_icon_dark));
nameTextView = (TextView) view.findViewById(R.id.nameTextView);
amenityTagTextView = (TextView) view.findViewById(R.id.amenityTagTextView);
@ -77,7 +75,7 @@ public class AdvancedEditPoiFragment extends Fragment
LinearLayout editTagsLineaLayout =
(LinearLayout) view.findViewById(R.id.editTagsList);
final MapPoiTypes mapPoiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
final MapPoiTypes mapPoiTypes = getMyApplication().getPoiTypes();
mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData());
// It is possible to not restart initialization every time, and probably move initialization to appInit
Map<String, PoiType> translatedTypes = getData().getAllTranslatedSubTypes();

View file

@ -5,7 +5,6 @@ import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
@ -23,9 +22,8 @@ import android.widget.TextView;
import net.osmand.PlatformUtil;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.osmedit.dialogs.OpeningHoursDaysDialogFragment;
import net.osmand.plus.osmedit.dialogs.OpeningHoursHoursDialogFragment;
import net.osmand.util.Algorithms;
@ -36,7 +34,7 @@ import org.apache.commons.logging.Log;
import gnu.trove.list.array.TIntArrayList;
public class BasicEditPoiFragment extends Fragment
public class BasicEditPoiFragment extends BaseOsmAndFragment
implements EditPoiDialogFragment.OnFragmentActivatedListener {
private static final Log LOG = PlatformUtil.getLog(BasicEditPoiFragment.class);
private static final String OPENING_HOURS = "opening_hours";
@ -63,26 +61,24 @@ public class BasicEditPoiFragment extends Fragment
theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true);
int iconColor = typedValue.data;
IconsCache iconsCache = getMyApplication().getIconsCache();
ImageView streetImageView = (ImageView) view.findViewById(R.id.streetImageView);
streetImageView.setImageDrawable(
iconsCache.getPaintedContentIcon(R.drawable.ic_action_street_name, iconColor));
getPaintedContentIcon(R.drawable.ic_action_street_name, iconColor));
ImageView houseNumberImageView = (ImageView) view.findViewById(R.id.houseNumberImageView);
houseNumberImageView.setImageDrawable(
iconsCache.getPaintedContentIcon(R.drawable.ic_action_building_number, iconColor));
getPaintedContentIcon(R.drawable.ic_action_building_number, iconColor));
ImageView phoneImageView = (ImageView) view.findViewById(R.id.phoneImageView);
phoneImageView.setImageDrawable(
iconsCache.getPaintedContentIcon(R.drawable.ic_action_call_dark, iconColor));
getPaintedContentIcon(R.drawable.ic_action_call_dark, iconColor));
ImageView webSiteImageView = (ImageView) view.findViewById(R.id.webSiteImageView);
webSiteImageView.setImageDrawable(
iconsCache.getPaintedContentIcon(R.drawable.ic_world_globe_dark, iconColor));
getPaintedContentIcon(R.drawable.ic_world_globe_dark, iconColor));
ImageView descriptionImageView = (ImageView) view.findViewById(R.id.descriptionImageView);
descriptionImageView.setImageDrawable(
iconsCache.getPaintedContentIcon(R.drawable.ic_action_description, iconColor));
getPaintedContentIcon(R.drawable.ic_action_description, iconColor));
ImageView openingHoursImageView = (ImageView) view.findViewById(R.id.openingHoursImageView);
openingHoursImageView.setImageDrawable(
iconsCache.getPaintedContentIcon(R.drawable.ic_action_time, iconColor));
getPaintedContentIcon(R.drawable.ic_action_time, iconColor));
streetEditText = (EditText) view.findViewById(R.id.streetEditText);
houseNumberEditText = (EditText) view.findViewById(R.id.houseNumberEditText);
@ -106,10 +102,8 @@ public class BasicEditPoiFragment extends Fragment
}
});
LinearLayout openHoursContainer = (LinearLayout) view.findViewById(R.id.openHoursContainer);
Drawable clockDrawable = iconsCache
.getPaintedContentIcon(R.drawable.ic_action_time, iconColor);
Drawable deleteDrawable = iconsCache
.getPaintedContentIcon(R.drawable.ic_action_remove_dark, iconColor);
Drawable clockDrawable = getPaintedContentIcon(R.drawable.ic_action_time, iconColor);
Drawable deleteDrawable = getPaintedContentIcon(R.drawable.ic_action_remove_dark, iconColor);
if (savedInstanceState != null && savedInstanceState.containsKey(OPENING_HOURS)) {
mOpeningHoursAdapter = new OpeningHoursAdapter(
(OpeningHoursParser.OpeningHours) savedInstanceState.getSerializable(OPENING_HOURS),
@ -123,10 +117,6 @@ public class BasicEditPoiFragment extends Fragment
return view;
}
private OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}
protected void addTextWatcher(final String tag, final EditText e) {
e.addTextChangedListener(new TextWatcher() {

View file

@ -37,8 +37,8 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.ActionBarProgressActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.base.OsmAndListFragment;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.dialogs.ProgressDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;