Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### ~
* adds option to show data source label in app UI / misc data source related UI enhancements.
* adds Hungarian translation (contributed by Erci) (#106).

### v0.4.1 (2017-10-31)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.util.Log;
import android.view.View;

import com.forrestguice.suntimeswidget.calculator.SuntimesCalculatorDescriptor;
import com.forrestguice.suntimeswidget.calculator.SuntimesRiseSetDataset;
import com.forrestguice.suntimeswidget.notes.NoteData;
import com.forrestguice.suntimeswidget.settings.AppSettings;
Expand All @@ -46,13 +47,15 @@
import static android.support.test.espresso.Espresso.unregisterIdlingResources;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.longClick;
import static android.support.test.espresso.action.ViewActions.pressBack;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.action.ViewActions.swipeLeft;
import static android.support.test.espresso.action.ViewActions.swipeRight;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isRoot;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.forrestguice.suntimeswidget.AlarmDialogTest.cancelAlarmDialog;
Expand All @@ -63,6 +66,7 @@
import static com.forrestguice.suntimeswidget.LocationDialogTest.applyLocationDialog;
import static com.forrestguice.suntimeswidget.LocationDialogTest.inputLocationDialog_mode;
import static com.forrestguice.suntimeswidget.LocationDialogTest.showLocationDialog;
import static com.forrestguice.suntimeswidget.SuntimesSettingsActivityTest.verifyGeneralSettings;
import static com.forrestguice.suntimeswidget.TimeDateDialogTest.applyDateDialog;
import static com.forrestguice.suntimeswidget.TimeDateDialogTest.cancelDateDialog;
import static com.forrestguice.suntimeswidget.TimeDateDialogTest.inputDateDialog_date;
Expand Down Expand Up @@ -106,6 +110,7 @@ public void verifyActivity()
verifyNote(activityRule.getActivity());
verifyTimeCard();
verifyLightmap(activityRule.getActivity());
verifyDataSourceUI(activityRule.getActivity());
}

public static void verifyTheme(SuntimesActivity activity)
Expand Down Expand Up @@ -182,6 +187,41 @@ public static void verifyLightmap(Context context)
}
}

public static void verifyDataSourceUI(Context context)
{
if (AppSettings.loadDatasourceUIPref(context))
{
onView(withId(R.id.txt_datasource)).check(assertShown);

SuntimesCalculatorDescriptor dataSource = WidgetSettings.loadCalculatorModePref(context, 0);
if (dataSource != null)
{
onView(withId(R.id.txt_datasource)).check(matches(withText(dataSource.name())));
}
// else { // TODO: test conditions when dataSource==null }

} else {
onView(withId(R.id.txt_datasource)).check(matches(not(isDisplayed())));
}
}

/**
* UI Test
*
* Click on the data source label and verify setting activity is displayed.
*/
@Test
public void test_onDataSourceUIClick()
{
verifyDataSourceUI(activityRule.getActivity());
if (AppSettings.loadDatasourceUIPref(activityRule.getActivity()))
{
onView(withId(R.id.txt_datasource)).perform(click());
verifyGeneralSettings(activityRule.getActivity());
onView(isRoot()).perform(pressBack());
}
}

/**
* UI Test
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ public static void showGeneralSettings(Activity activity)
public static void verifyGeneralSettings(Context context)
{
verifyGeneralSettings_dataSource(context);
verifyGeneralSettings_gpsTimeLimit(context);
verifyGeneralSettings_gpsMaxAge(context);
}

public static void verifyGeneralSettings_dataSource(Context context)
Expand All @@ -143,11 +141,11 @@ public static void verifyGeneralSettings_dataSource(Context context)
dataSourcePref.check(assertEnabled);

SuntimesCalculatorDescriptor dataSource = WidgetSettings.loadCalculatorModePref(context, 0);
DataInteraction dataSourcePref_text = dataSourcePref.onChildView(allOf(withClassName(is(TextView.class.getName())), withText(dataSource.getDisplayString())));
DataInteraction dataSourcePref_text = dataSourcePref.onChildView(allOf(withClassName(is(TextView.class.getName())), withText(dataSource.name())));
dataSourcePref_text.check(assertShown);
}

public static void verifyGeneralSettings_gpsTimeLimit(Context context)
public static void verifyPlacesSettings_gpsTimeLimit(Context context)
{
DataInteraction gpsTimePref = onData(
allOf( is(instanceOf(Preference.class)), withKey("getFix_maxElapsed")) )
Expand All @@ -156,7 +154,7 @@ public static void verifyGeneralSettings_gpsTimeLimit(Context context)
// TODO: verify correct setting
}

public static void verifyGeneralSettings_gpsMaxAge(Context context)
public static void verifyPlacesSettings_gpsMaxAge(Context context)
{
DataInteraction gpsAgePref = onData(
allOf( is(instanceOf(Preference.class)), withKey("getFix_maxAge")) )
Expand Down Expand Up @@ -232,6 +230,8 @@ public static void showPlacesSettings(Activity activity)

public static void verifyPlacesSettings(Context context)
{
verifyPlacesSettings_gpsTimeLimit(context);
verifyPlacesSettings_gpsMaxAge(context);
onView(withText(context.getString(R.string.configLabel_places_export))).check(assertEnabled);
onView(withText(context.getString(R.string.configLabel_places_clear))).check(assertEnabled);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import android.os.Bundle;

import android.os.Parcelable;
import android.preference.PreferenceActivity;
import android.provider.CalendarContract;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
Expand Down Expand Up @@ -184,6 +185,9 @@ public class SuntimesActivity extends AppCompatActivity
private LightMapView lightmap;
private View lightmapLayout;

private TextView txt_datasource;
private View layout_datasource;

private boolean isRtl = false;
private boolean userSwappedCard = false;
private HashMap<SolarEvents.SolarEventField, TextView> timeFields;
Expand Down Expand Up @@ -394,6 +398,7 @@ protected void initViews(Context context)
initNoteViews(context);
initCardViews(context);
initLightMap(context);
initMisc(context);
}

/**
Expand Down Expand Up @@ -446,6 +451,34 @@ public boolean onLongClick(View view)
});
}

private void initMisc(Context context)
{
layout_datasource = findViewById(R.id.layout_datasource);

txt_datasource = (TextView)findViewById(R.id.txt_datasource);
if (txt_datasource != null)
{
txt_datasource.setClickable(true);
txt_datasource.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
showGeneralSettings();
}
});
txt_datasource.setOnLongClickListener(new View.OnLongClickListener()
{
@Override
public boolean onLongClick(View view)
{
showGeneralSettings();
return true;
}
});
}
}

/**
* initialize gps helper
*/
Expand Down Expand Up @@ -1064,6 +1097,19 @@ protected void showSettings()
Intent settingsIntent = new Intent(this, SuntimesSettingsActivity.class);
startActivity(settingsIntent);
}
protected void showGeneralSettings()
{
Intent settingsIntent = new Intent(this, SuntimesSettingsActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
settingsIntent.putExtra( PreferenceActivity.EXTRA_SHOW_FRAGMENT, SuntimesSettingsActivity.GeneralPrefsFragment.class.getName() );
settingsIntent.putExtra( PreferenceActivity.EXTRA_NO_HEADERS, true );

} else {
settingsIntent.setAction(SuntimesSettingsActivity.ACTION_PREFS_GENERAL);
}
startActivity(settingsIntent);
}

/**
* Show the alarm dialog.
Expand Down Expand Up @@ -1289,6 +1335,13 @@ protected void updateViews( Context context )
SpannableStringBuilder timezoneSpan = SuntimesUtils.createSpan(this, timezoneString, timezoneTags);
txt_timezone.setText(timezoneSpan);

// datasource ui
if (txt_datasource != null)
{
txt_datasource.setText(dataset.dataActual.calculator().name());
}
showDatasourceUI(AppSettings.loadDatasourceUIPref(this));

// "light map"
boolean enableLightMap = AppSettings.loadShowLightmapPref(this);
showLightMap(enableLightMap);
Expand Down Expand Up @@ -1699,6 +1752,17 @@ protected void showLightMapDialog()
lightMapDialog.show(getSupportFragmentManager(), DIALOGTAG_LIGHTMAP);
}

/**
* Show data source labels / ui.
*/
protected void showDatasourceUI( boolean value )
{
if (layout_datasource != null)
{
layout_datasource.setVisibility((value ? View.VISIBLE : View.GONE));
}
}

/**
* @param tomorrow true is "tomorrow" date field, false is "today" date field
* @return an OnClickListener for the specified date field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ protected void loadGeneralSettings(Context context)
{
// load: calculator mode
SuntimesCalculatorDescriptor calculatorMode = WidgetSettings.loadCalculatorModePref(context, appWidgetId);
spinner_calculatorMode.setSelection(calculatorMode.ordinal());
spinner_calculatorMode.setSelection((calculatorMode != null ? calculatorMode.ordinal() : 0));

// load: compare mode
WidgetSettings.CompareMode compareMode = WidgetSettings.loadCompareModePref(context, appWidgetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.forrestguice.suntimeswidget.getfix.ClearPlacesTask;
import com.forrestguice.suntimeswidget.getfix.ExportPlacesTask;
import com.forrestguice.suntimeswidget.settings.AppSettings;
import com.forrestguice.suntimeswidget.settings.SummaryListPreference;
import com.forrestguice.suntimeswidget.settings.WidgetSettings;

import java.io.File;
Expand Down Expand Up @@ -267,7 +268,7 @@ protected void rebuildActivity()
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class GeneralPrefsFragment extends PreferenceFragment
{
private ListPreference calculatorPref;
private SummaryListPreference calculatorPref;

@Override
public void onCreate(Bundle savedInstanceState)
Expand All @@ -279,7 +280,7 @@ public void onCreate(Bundle savedInstanceState)
PreferenceManager.setDefaultValues(getActivity(), R.xml.preference_general, false);
addPreferencesFromResource(R.xml.preference_general);

calculatorPref = (ListPreference) findPreference("appwidget_0_general_calculator");
calculatorPref = (SummaryListPreference) findPreference("appwidget_0_general_calculator");
initPref_general(GeneralPrefsFragment.this);
}

Expand Down Expand Up @@ -312,46 +313,51 @@ private void initPref_general()

String key = WidgetSettings.PREF_PREFIX_KEY + "0" + WidgetSettings.PREF_PREFIX_KEY_GENERAL + WidgetSettings.PREF_KEY_GENERAL_CALCULATOR;
//noinspection deprecation
ListPreference calculatorPref = (ListPreference)findPreference(key);
SummaryListPreference calculatorPref = (SummaryListPreference)findPreference(key);
if (calculatorPref != null)
{
initPref_general(calculatorPref);
initPref_general(this, calculatorPref);
loadPref_general(this, calculatorPref);
}
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void initPref_general(PreferenceFragment fragment)
{
String key = WidgetSettings.PREF_PREFIX_KEY + "0" + WidgetSettings.PREF_PREFIX_KEY_GENERAL + WidgetSettings.PREF_KEY_GENERAL_CALCULATOR;
ListPreference calculatorPref = (ListPreference) fragment.findPreference(key);
SummaryListPreference calculatorPref = (SummaryListPreference) fragment.findPreference(key);
if (calculatorPref != null)
{
initPref_general(calculatorPref);
loadPref_general(fragment.getActivity(), calculatorPref);
Context context = fragment.getActivity();
initPref_general(context, calculatorPref);
loadPref_general(context, calculatorPref);
}
}
private static void initPref_general(final ListPreference calculatorPref)
private static void initPref_general(Context context, final SummaryListPreference calculatorPref)
{
SuntimesCalculatorDescriptor[] calculators = SuntimesCalculatorDescriptor.values();
String[] calculatorEntries = new String[calculators.length];
String[] calculatorValues = new String[calculators.length];
String[] calculatorSummaries = new String[calculators.length];

int i = 0;
for (SuntimesCalculatorDescriptor calculator : calculators)
{
calculator.initDisplayStrings(context);
calculatorEntries[i] = calculatorValues[i] = calculator.name();
calculatorSummaries[i] = calculator.getDisplayString();
i++;
}

calculatorPref.setEntries(calculatorEntries);
calculatorPref.setEntryValues(calculatorValues);
calculatorPref.setEntrySummaries(calculatorSummaries);
}
private static void loadPref_general(Context context, ListPreference calculatorPref)
private static void loadPref_general(Context context, SummaryListPreference calculatorPref)
{
if (context != null && calculatorPref != null)
{
SuntimesCalculatorDescriptor currentMode = WidgetSettings.loadCalculatorModePref(context, 0);
int currentIndex = calculatorPref.findIndexOfValue(currentMode.name());
int currentIndex = ((currentMode != null) ? calculatorPref.findIndexOfValue(currentMode.name()) : 0);
calculatorPref.setValueIndex(currentIndex);
//Log.d("SuntimesSettings", "current mode: " + currentMode + " (" + currentIndex + ")");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public String displayStringForTitlePattern(String titlePattern, SuntimesRiseSetD
WidgetSettings.TimeMode timeMode = data.timeMode();
WidgetSettings.Location location = data.location();
String timezoneID = data.timezone().getID();
String datasource = data.calculatorMode().getDisplayString();
String datasource = (data.calculatorMode() == null) ? "" : data.calculatorMode().name();

String displayString = titlePattern;
displayString = displayString.replaceAll(modePatternShort, timeMode.getShortDisplayString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public static WidgetListAdapter createWidgetListAdapter(Context context)
String widgetTitle = utils.displayStringForTitlePattern(titlePattern, data);
String title = context.getString(R.string.configLabel_widgetList_itemTitle, widgetTitle);
String type = context.getString(R.string.app_name_widget0);
String source = data.calculatorMode().getDisplayString();
String source = ((data.calculatorMode() == null) ? "def" : data.calculatorMode().name());
String summary = context.getString(R.string.configLabel_widgetList_itemSummaryPattern, type, source);

try {
Expand All @@ -328,7 +328,7 @@ public static WidgetListAdapter createWidgetListAdapter(Context context)
String widgetTitle = utils.displayStringForTitlePattern(titlePattern, data);
String title = context.getString(R.string.configLabel_widgetList_itemTitle, widgetTitle);
String type = context.getString(R.string.app_name_widget1);
String source = data.calculatorMode().getDisplayString();
String source = ((data.calculatorMode() == null) ? "def" : data.calculatorMode().name());
String summary = context.getString(R.string.configLabel_widgetList_itemSummaryPattern, type, source);

try {
Expand Down
Loading