Skip to content

Commit

Permalink
show comparison
Browse files Browse the repository at this point in the history
implements "show comparison" and "compare against" app options (#773)
  • Loading branch information
forrestguice committed Mar 16, 2024
1 parent dcadca0 commit 1fbfd73
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ protected Pair<SuntimesRiseSetDataset, SuntimesMoonData> createData(Context cont
sun.putData(eventID, d);
}
sun.setTodayIs(date);
for (String id : sun.getDataModes()) {
sun.getData(id).setCompareMode(options.comparisonMode);
}
sun.calculateData();

SuntimesMoonData moon = null;
Expand Down Expand Up @@ -597,6 +600,8 @@ public static class CardAdapterOptions
public boolean showWarnings = AppSettings.PREF_DEF_UI_SHOWWARNINGS;
public boolean showMoon = AppSettings.PREF_DEF_UI_SHOWMOON;
public boolean showLightmap = AppSettings.PREF_DEF_UI_SHOWLIGHTMAP;
public boolean showComparison = WidgetSettings.PREF_DEF_GENERAL_SHOWCOMPARE;
public WidgetSettings.CompareMode comparisonMode = WidgetSettings.PREF_DEF_GENERAL_COMPAREMODE;

public boolean[] showFields = null;
public boolean showActual = true;
Expand Down Expand Up @@ -631,6 +636,8 @@ public void init(Context context)
showWarnings = AppSettings.loadShowWarningsPref(context);
showMoon = AppSettings.loadShowMoonPref(context);
showLightmap = AppSettings.loadShowLightmapPref(context);
showComparison = WidgetSettings.loadShowComparePref(context, 0);
comparisonMode = WidgetSettings.loadCompareModePref(context, 0);

showFields = AppSettings.loadShowFieldsPref(context);
showActual = showFields[AppSettings.FIELD_ACTUAL];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public class CardViewHolder extends RecyclerView.ViewHolder
public LightMapView lightmap;
public View lightmapLayout;

public TextView txt_comparison;

public int position = RecyclerView.NO_POSITION;

public CardViewHolder(View view, CardAdapter.CardAdapterOptions options)
Expand Down Expand Up @@ -136,6 +138,8 @@ public CardViewHolder(View view, CardAdapter.CardAdapterOptions options)
moonrise = (MoonRiseSetView) view.findViewById(R.id.moonriseset_view);
moonrise.setShowExtraField(false);

txt_comparison = (TextView) view.findViewById(R.id.text_comparison);

rows = new ArrayList<>();
rows.add(row_actual = new TimeFieldRow(view, R.id.text_time_label_official, R.id.text_time_sunrise_actual, R.id.text_time_sunset_actual));
rows.add(row_civil = new TimeFieldRow(view, R.id.text_time_label_civil, R.id.text_time_sunrise_civil, R.id.text_time_sunset_civil));
Expand Down Expand Up @@ -298,6 +302,11 @@ public void bindDataToPosition(@NonNull Context context, int position, Pair<Sunt
updateDayLengthViews(context, txt_daylength, sun.dataActual.dayLengthToday(), R.string.length_day, options.showSeconds, options.color_textTimeDelta);
updateDayLengthViews(context, txt_lightlength, sun.dataCivil.dayLengthToday(), R.string.length_light, options.showSeconds, options.color_textTimeDelta);

if (txt_comparison != null) {
txt_comparison.setVisibility(options.showComparison ? View.VISIBLE : View.GONE);
txt_comparison.setText(options.showComparison ? comparisonDisplayString(context, sun.dataActual, options) : "");
}

// date field
Date data_date = sun.dataActual.date();
DateFormat dateFormat = android.text.format.DateFormat.getMediumDateFormat(context.getApplicationContext()); // Apr 11, 2016
Expand Down Expand Up @@ -358,6 +367,14 @@ public void bindDataToPosition(@NonNull Context context, int position, Pair<Sunt
toggleNextPrevButtons(position);
}

protected CharSequence comparisonDisplayString(Context context, SuntimesRiseSetData data, CardAdapter.CardAdapterOptions options)
{
SuntimesUtils.TimeDisplayText deltaText = utils.timeDeltaLongDisplayString(data.dayLengthToday(), data.dayLengthOther(), true);
String deltaString = deltaText.getValue() + " " + deltaText.getUnits();
String compareString = data.dayDeltaPrefix() + " " + deltaString + deltaText.getSuffix();
return SuntimesUtils.createBoldColorSpan(null, compareString, deltaString, options.color_textTimeDelta);
}

public void toggleNextPrevButtons(int position)
{
int offset = (position - CardAdapter.TODAY_POSITION);
Expand Down
26 changes: 20 additions & 6 deletions app/src/main/res/layout/info_time_card1b.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/info_time_all_today"
android:layout_width="match_parent" android:layout_height="wrap_content">
android:layout_width="match_parent"
android:layout_height="wrap_content">

<!-- card scroller -->
<com.forrestguice.suntimeswidget.SuntimesCardScroll android:id="@+id/cardContent"
Expand All @@ -23,12 +25,24 @@
<include layout="@layout/info_time_all" />

<!-- day length -->
<LinearLayout android:id="@+id/layout_daylength"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="7dp">
<LinearLayout
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="horizontal" android:layout_marginTop="7dp">

<LinearLayout android:id="@+id/layout_daylength"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical">

<include layout="@layout/info_time_daylength" />

</LinearLayout>

<include layout="@layout/info_time_daylength" />
<TextView android:id="@+id/text_comparison"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginStart="16dp" android:layout_marginEnd="32dp"
android:textSize="?attr/text_size_small"
tools:text="Tomorrow will be 1min 30s longer" />

</LinearLayout>

Expand Down

0 comments on commit 1fbfd73

Please sign in to comment.