Mechanism for changing number of rows in cards is implemented.

Currently only favourites fragment uses this functionality.
Dark theme for Dashboard Options dialog.
This commit is contained in:
GaidamakUA 2015-09-01 11:43:19 +03:00
parent 960ca8331a
commit 9cbb5c185a
7 changed files with 93 additions and 22 deletions

View file

@ -4,21 +4,22 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/dialog_content_margin"
android:paddingRight="@dimen/dialog_content_margin">
android:orientation="vertical">
<include layout="@layout/dashboard_settings_dialog_item"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:gravity="top">
<TextView
android:id="@+id/numberOfRowsTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Number of rows %s"/>
android:layout_marginLeft="@dimen/dialog_content_margin"
tools:text="@string/number_of_rows_in_dash"
android:layout_gravity="top"/>
<Space
android:layout_width="0dp"
@ -31,7 +32,8 @@
android:layout_width="48dp"
android:layout_height="wrap_content"
android:padding="0dp"
android:text="-" />
android:gravity="center_horizontal"
android:text="-"/>
<Button
android:id="@+id/incrementButton"
@ -39,7 +41,8 @@
android:layout_width="48dp"
android:layout_height="wrap_content"
android:padding="0dp"
android:text="+" />
android:gravity="center_horizontal"
android:text="+"/>
</LinearLayout>
</LinearLayout>

View file

@ -33,7 +33,7 @@
android:id="@+id/toolbar_settings"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="left"
android:layout_gravity="right"
android:background="@drawable/dashboard_button_light"
android:scaleType="center"
android:src="@drawable/ic_action_settings"/>

View file

@ -32,6 +32,8 @@
<attr name="osmo_header_background" format="color"/>
<attr name="dashboard_subheader_text_color" format="color"/>
<attr name="dashboard_general_button_text_color" format="color"/>
<attr name="dialog_inactive_text_color" format="reference"/>
</declare-styleable>
<declare-styleable name="PagerSlidingTabStrip">

View file

@ -157,4 +157,5 @@
<color name="divider_color">#ccc</color>
<color name="color_dialog_buttons">#2f7af5</color>
<color name="dialog_inactive_text_color_dark">#78909c</color>
</resources>

View file

@ -2254,4 +2254,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="description">Description</string>
<string name="add_opening_hours">Add opening hours</string>
<string name="poi_dialog_poi_type">POI Type</string>
<string name="number_of_rows_in_dash">Number of rows in dash %1$s</string>
</resources>

View file

@ -103,6 +103,8 @@
<item name="android:actionModeCloseDrawable">@drawable/ic_action_mode_back</item>
<item name="android:actionModeStyle">@style/WhiteActionMode</item>
<item name="android:actionMenuTextColor">@color/color_white</item>
<item name="dialog_inactive_text_color">@color/icon_color_light</item>
</style>
<style name="OsmandLightTheme.DarkActionbar">
@ -163,6 +165,8 @@
<item name="android:actionModeBackground">@color/actionbar_dark_color</item>
<item name="android:actionBarStyle">@style/Widget.Styled.ActionBarDark</item>
<item name="dialog_inactive_text_color">@color/dialog_inactive_text_color_dark</item>
</style>

View file

@ -1,13 +1,15 @@
package net.osmand.plus.dashboard.tools;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -29,9 +31,12 @@ import java.util.List;
public class DashboardSettingsDialogFragment extends DialogFragment {
private static final String CHECKED_ITEMS = "checked_items";
private static final String NUMBER_OF_ROWS_ARRAY = "number_of_rows_array";
private MapActivity mapActivity;
private ArrayList<DashFragmentData> mFragmentsData;
private DashFragmentAdapter mAdapter;
private int textColorPrimary;
private int textColorSecondary;
@Override
public void onAttach(Activity activity) {
@ -48,6 +53,13 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = getActivity().getTheme();
theme.resolveAttribute(android.R.attr.textColorPrimary, typedValue, true);
textColorPrimary = typedValue.data;
theme.resolveAttribute(R.attr.dialog_inactive_text_color, typedValue, true);
textColorSecondary = typedValue.data;
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
View view = LayoutInflater.from(getActivity()).inflate(
@ -58,12 +70,13 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
settings.registerBooleanPreference(MapActivity.SHOULD_SHOW_DASHBOARD_ON_START, true);
final CompoundButton compoundButton = (CompoundButton) view.findViewById(R.id.check_item);
compoundButton.setChecked(shouldShowDashboardOnStart.get());
textView.setTextColor(shouldShowDashboardOnStart.get() ? 0xFF212121 : 0xFF8c8c8c);
textView.setTextColor(shouldShowDashboardOnStart.get() ? textColorPrimary
: textColorSecondary);
compoundButton.setOnCheckedChangeListener(
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
textView.setTextColor(b ? 0xFF212121 : 0xFF8c8c8c);
textView.setTextColor(b ? textColorPrimary : textColorSecondary);
}
});
@ -71,7 +84,7 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
if (savedInstanceState != null && savedInstanceState.containsKey(CHECKED_ITEMS)) {
mAdapter = new DashFragmentAdapter(getActivity(), mFragmentsData,
savedInstanceState.getBooleanArray(CHECKED_ITEMS),
new int[mFragmentsData.size()]);
savedInstanceState.getIntArray(NUMBER_OF_ROWS_ARRAY));
} else {
mAdapter = new DashFragmentAdapter(getActivity(), mFragmentsData,
settings);
@ -82,10 +95,15 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
@Override
public void onClick(DialogInterface dialogInterface, int type) {
boolean[] shouldShow = mAdapter.getCheckedItems();
int[] numberOfRows = mAdapter.getNumbersOfRows();
for (int i = 0; i < shouldShow.length; i++) {
settings.registerBooleanPreference(
DashboardOnMap.SHOULD_SHOW + mFragmentsData.get(i).tag, true)
.makeGlobal().set(shouldShow[i]);
if (mFragmentsData.get(i).rowNumberTag != null) {
settings.registerIntPreference(mFragmentsData.get(i).rowNumberTag, 5)
.makeGlobal().set(numberOfRows[i]);
}
}
mapActivity.getDashboard().refreshDashboardFragments();
shouldShowDashboardOnStart.set(compoundButton.isChecked());
@ -102,28 +120,36 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putBooleanArray(CHECKED_ITEMS, mAdapter.getCheckedItems());
outState.putIntArray(NUMBER_OF_ROWS_ARRAY, mAdapter.getNumbersOfRows());
super.onSaveInstanceState(outState);
}
private static class DashFragmentAdapter extends ArrayAdapter<DashFragmentData> {
private class DashFragmentAdapter extends ArrayAdapter<DashFragmentData> {
private final boolean[] checkedItems;
private final int[] numbersOfRows;
public DashFragmentAdapter(Context context, List<DashFragmentData> objects,
boolean[] checkedItems, int[] numbersOfRows) {
public DashFragmentAdapter(@NonNull Context context,
@NonNull List<DashFragmentData> objects,
@NonNull boolean[] checkedItems,
@NonNull int[] numbersOfRows) {
super(context, 0, objects);
this.checkedItems = checkedItems;
this.numbersOfRows = numbersOfRows;
}
public DashFragmentAdapter(Context context, List<DashFragmentData> objects,
OsmandSettings settings) {
public DashFragmentAdapter(@NonNull Context context,
@NonNull List<DashFragmentData> objects,
@NonNull OsmandSettings settings) {
super(context, 0, objects);
numbersOfRows = new int[objects.size()];
checkedItems = new boolean[objects.size()];
for (int i = 0; i < objects.size(); i++) {
checkedItems[i] = settings.registerBooleanPreference(
DashboardOnMap.SHOULD_SHOW + objects.get(i).tag, true).makeGlobal().get();
if (objects.get(i).tag != null) {
numbersOfRows[i] = settings.registerIntPreference(objects.get(i).rowNumberTag, 5)
.makeGlobal().get();
}
}
}
@ -140,8 +166,8 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
DashFragmentData dashFragmentData = getItem(position);
DashViewHolder viewHolder;
boolean hasRows = false;//getItemViewType(position) == 1;
final DashViewHolder viewHolder;
boolean hasRows = getItemViewType(position) == 1;
if (convertView == null) {
viewHolder = new DashViewHolder();
if (hasRows) {
@ -164,18 +190,48 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
DashViewHolder localViewHolder = (DashViewHolder) compoundButton.getTag();
checkedItems[localViewHolder.position] = b;
localViewHolder.textView.setTextColor(
checkedItems[localViewHolder.position] ? 0xFF212121
: 0xFF8c8c8c);
checkedItems[localViewHolder.position] ? textColorPrimary
: textColorSecondary);
}
});
} else {
viewHolder = (DashViewHolder) convertView.getTag();
}
if (hasRows) {
viewHolder.incrementButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DashViewHolder localViewHolder = (DashViewHolder) v.getTag();
numbersOfRows[localViewHolder.position]++;
viewHolder.numberOfRowsTextView.setText(
getString(R.string.number_of_rows_in_dash,
numbersOfRows[localViewHolder.position]));
}
});
viewHolder.incrementButton.setTag(viewHolder);
viewHolder.decrementButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DashViewHolder localViewHolder = (DashViewHolder) v.getTag();
if (numbersOfRows[localViewHolder.position] > 1) {
numbersOfRows[localViewHolder.position]--;
}
viewHolder.numberOfRowsTextView.setText(
getString(R.string.number_of_rows_in_dash,
numbersOfRows[localViewHolder.position]));
}
});
viewHolder.decrementButton.setTag(viewHolder);
viewHolder.numberOfRowsTextView.setText(
getString(R.string.number_of_rows_in_dash,
numbersOfRows[position]));
}
viewHolder.position = position;
viewHolder.compoundButton.setTag(viewHolder);
viewHolder.compoundButton.setChecked(checkedItems[position]);
viewHolder.textView.setText(dashFragmentData.title);
viewHolder.textView.setTextColor(checkedItems[position] ? 0xFF212121 : 0xFF8c8c8c);
viewHolder.textView.setTextColor(checkedItems[position] ? textColorPrimary :
textColorSecondary);
convertView.setTag(viewHolder);
return convertView;
}
@ -184,6 +240,10 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
return checkedItems;
}
public int[] getNumbersOfRows() {
return numbersOfRows;
}
private class DashViewHolder {
TextView textView;
CompoundButton compoundButton;