Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Show Date picker dialog instead of scrolling to today #85

Merged
merged 4 commits into from
Jan 30, 2017
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
11 changes: 2 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,10 @@ if [ ! -f secret.gradle ]; then
fi

# Copy mock google-services file if necessary
if [ ! -f ./mobile/src/free/google-services.json ]; then
if [ ! -f ./mobile/google-services.json ]; then
echo "Using mock google-services.json for free"
mkdir ./mobile/src/free/
cp mock-google-services.json ./mobile/src/free/google-services.json
cp mock-google-services.json ./mobile/google-services.json
fi
if [ ! -f ./mobile/src/pro/google-services.json ]; then
echo "Using mock google-services.json for pro"
mkdir ./mobile/src/pro/
cp mock-google-services.json ./mobile/src/pro/google-services.json
fi

# Build
if [ $TRAVIS_PULL_REQUEST = false ] ; then
# For a merged commit, build all configurations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public enum Action {
DONATION("donate"),
INTERACT_CONTACT("contact"),
SELECT_THEME("theme"),
GO_TO_TODAY("gotoday"),
SELECT_DATE("select_date"),
COMPLICATION("complication: contacts events");

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.alexstyl.specialdates.ErrorTracker;
import com.alexstyl.specialdates.Optional;
import com.alexstyl.specialdates.R;
import com.alexstyl.specialdates.analytics.AnalyticsProvider;
import com.alexstyl.specialdates.analytics.Screen;
import com.alexstyl.specialdates.date.Date;
import com.alexstyl.specialdates.date.DateFormatUtils;
import com.alexstyl.specialdates.support.AskForSupport;
Expand All @@ -35,6 +37,8 @@ public class DateDetailsActivity extends ThemedActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_date_details);

AnalyticsProvider.getAnalytics(this).trackScreen(Screen.DATE_DETAILS);
MementoToolbar toolbar = Views.findById(this, R.id.memento_toolbar);
toolbar.displayAsUp();
setSupportActionBar(toolbar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.util.Locale;

final class DumbTestResources implements StringResources {
public final class DumbTestResources implements StringResources {
@Override
public String getString(@StringRes int id) {
switch (id) {
Expand All @@ -20,6 +20,10 @@ public String getString(@StringRes int id) {
return "Anniversary";
case R.string.Other:
return "Other";
case R.string.tomorrow:
return "Tomorrow";
case R.string.today:
return "Today";
}
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.alexstyl.specialdates.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.view.Menu;
Expand All @@ -9,16 +10,20 @@

import com.alexstyl.specialdates.ExternalNavigator;
import com.alexstyl.specialdates.R;
import com.alexstyl.specialdates.analytics.Action;
import com.alexstyl.specialdates.analytics.Analytics;
import com.alexstyl.specialdates.analytics.AnalyticsProvider;
import com.alexstyl.specialdates.analytics.Screen;
import com.alexstyl.specialdates.date.Date;
import com.alexstyl.specialdates.datedetails.DateDetailsActivity;
import com.alexstyl.specialdates.events.namedays.NamedayPreferences;
import com.alexstyl.specialdates.search.SearchHintCreator;
import com.alexstyl.specialdates.support.AskForSupport;
import com.alexstyl.specialdates.theming.ThemingPreferences;
import com.alexstyl.specialdates.theming.ThemeMonitor;
import com.alexstyl.specialdates.theming.ThemingPreferences;
import com.alexstyl.specialdates.ui.ViewFader;
import com.alexstyl.specialdates.ui.base.ThemedActivity;
import com.alexstyl.specialdates.upcoming.DatePickerDialogFragment;
import com.alexstyl.specialdates.upcoming.view.ExposedSearchToolbar;
import com.alexstyl.specialdates.util.Notifier;
import com.alexstyl.specialdates.widgetprovider.TodayWidgetProvider;
Expand All @@ -31,7 +36,7 @@
* The activity was first launched with MainActivity being in package.ui.activity
* For that reason, it needs to stay here so that we don't remove ourselves from the user's desktop
*/
public class MainActivity extends ThemedActivity {
public class MainActivity extends ThemedActivity implements DatePickerDialogFragment.OnDateSetListener {

private Notifier notifier;
private AskForSupport askForSupport;
Expand All @@ -40,14 +45,15 @@ public class MainActivity extends ThemedActivity {
private MainNavigator navigator;
private ExternalNavigator externalNavigator;
private SearchTransitioner searchTransitioner;
private Analytics analytics;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

themeMonitor = ThemeMonitor.startMonitoring(ThemingPreferences.newInstance(this));
Analytics analytics = AnalyticsProvider.getAnalytics(this);
analytics = AnalyticsProvider.getAnalytics(this);
analytics.trackScreen(Screen.HOME);

navigator = new MainNavigator(analytics, this);
Expand Down Expand Up @@ -96,19 +102,36 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_select_date:
showSelectDateDialog();
return true;
case R.id.action_settings:
navigator.toSettings();
break;
return true;
case R.id.action_about:
navigator.toAbout();
break;
return true;
case R.id.action_donate:
navigator.toDonate();
break;
return true;
}
return super.onOptionsItemSelected(item);
}

private void showSelectDateDialog() {
analytics.trackAction(Action.SELECT_DATE);
DatePickerDialogFragment
.newInstance(Date.today())
.show(getSupportFragmentManager(), "date_picker");
}

@Override
public void onDateSelected(Date dateSelected) {
navigator.toDateDetails(dateSelected);
Intent intent = DateDetailsActivity.getStartIntent(this, dateSelected);
startActivity(intent);
}

@Override
public boolean onSearchRequested() {
searchTransitioner.transitionToSearch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.alexstyl.specialdates.addevent.AddEventActivity;
import com.alexstyl.specialdates.analytics.Analytics;
import com.alexstyl.specialdates.analytics.Screen;
import com.alexstyl.specialdates.date.Date;
import com.alexstyl.specialdates.datedetails.DateDetailsActivity;
import com.alexstyl.specialdates.search.SearchActivity;
import com.alexstyl.specialdates.settings.MainPreferenceActivity;
import com.alexstyl.specialdates.theming.AttributeExtractor;
Expand All @@ -21,6 +23,7 @@
class MainNavigator {

private static final Uri SUPPORT_URL = Uri.parse("http://paypal.me/alexstyl");

private final AttributeExtractor attributeExtractor;
private final Analytics analytics;
private final Activity activity;
Expand Down Expand Up @@ -71,7 +74,7 @@ void toSettings() {
analytics.trackScreen(Screen.SETTINGS);
}

public void toSearch() {
void toSearch() {
Intent intent = new Intent(activity, SearchActivity.class);
activity.startActivity(intent);
}
Expand All @@ -83,4 +86,9 @@ public SimpleChromeCustomTabsIntentBuilder onCustomiseIntent(SimpleChromeCustomT
return simpleChromeCustomTabsIntentBuilder.withToolbarColor(toolbarColor);
}
};

void toDateDetails(Date dateSelected) {
Intent intent = DateDetailsActivity.getStartIntent(activity, dateSelected);
activity.startActivity(intent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.alexstyl.specialdates.upcoming;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.widget.DatePicker;

import com.alexstyl.specialdates.date.Date;
import com.alexstyl.specialdates.date.MonthInt;
import com.alexstyl.specialdates.ui.base.MementoDialog;
import com.novoda.notils.caster.Classes;

public final class DatePickerDialogFragment extends MementoDialog {

private static final String ARG_DAY_OF_MONTH = "day_of_month";
private static final String ARG_MONTH = "month";
private static final String ARG_YEAR = "year";

private OnDateSetListener listener;

public static DatePickerDialogFragment newInstance(Date startingDate) {
Bundle args = new Bundle();
args.putInt(ARG_DAY_OF_MONTH, startingDate.getDayOfMonth());
args.putInt(ARG_MONTH, startingDate.getMonth());
args.putInt(ARG_YEAR, startingDate.getYear());
DatePickerDialogFragment fragment = new DatePickerDialogFragment();
fragment.setArguments(args);
return fragment;
}

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
listener = Classes.from(activity);
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Date startingDate = getStartingDate();
return new DatePickerDialog(
getActivity(),
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
listener.onDateSelected(Date.on(dayOfMonth, toOneIndexedMonth(month), year));
}
},
startingDate.getYear(),
getZeroIndexedMonth(startingDate),
startingDate.getDayOfMonth()
);

}

@MonthInt
@SuppressWarnings("WrongConstant")
private int toOneIndexedMonth(@MonthInt int month) {
return month + 1;
}

private int getZeroIndexedMonth(Date startingDate) {
return startingDate.getMonth() - 1;
}

private Date getStartingDate() {
int dayOfMonth = getArguments().getInt(ARG_DAY_OF_MONTH);
@MonthInt int month = getArguments().getInt(ARG_MONTH);
int year = getArguments().getInt(ARG_YEAR);
return Date.on(dayOfMonth, month, year);
}

public interface OnDateSetListener {
void onDateSelected(Date dateSelected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GoToTodayEnabler {
}

void reattachTo(Menu menu) {
this.goToToday = menu.findItem(R.id.action_today);
this.goToToday = menu.findItem(R.id.action_select_date);
this.goToToday.setEnabled(showToday);
this.goToToday.setVisible(showToday);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import android.os.Bundle;
import android.support.transition.TransitionManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
Expand Down Expand Up @@ -43,7 +40,6 @@ public class UpcomingEventsFragment extends MementoFragment {
private SettingsMonitor monitor;
private UpcomingEventsProvider upcomingEventsProvider;
private boolean mustScrollToPosition = true;
private GoToTodayEnabler goToTodayEnabler;
private Analytics analytics;
private ContactPermissionRequest permissions;

Expand All @@ -54,7 +50,6 @@ public void onCreate(Bundle savedInstanceState) {
analytics = AnalyticsProvider.getAnalytics(getActivity());
monitor = SettingsMonitor.newInstance(getActivity());
monitor.initialise();
goToTodayEnabler = new GoToTodayEnabler(getMementoActivity());
upcomingEventsProvider = UpcomingEventsProvider.newInstance(getActivity(), onEventsLoadedListener);
PermissionChecker checker = new PermissionChecker(getActivity());
PermissionNavigator navigator = new PermissionNavigator(getActivity(), analytics);
Expand All @@ -76,30 +71,6 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
upcomingEventsListView.setHasFixedSize(true);
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_upcoming_dark, menu);
goToTodayEnabler.reattachTo(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_today:
goToToday();
return true;
default:
break;
}
return super.onOptionsItemSelected(item);
}

private void goToToday() {
analytics.trackAction(Action.GO_TO_TODAY);
upcomingEventsListView.scrollToToday(true);
}

private final PermissionCallbacks callbacks = new PermissionCallbacks() {
@Override
public void onPermissionGranted() {
Expand Down Expand Up @@ -194,9 +165,9 @@ public void onUpcomingEventsLoaded(List<UpcomingRowViewModel> dates) {
upcomingEventsListView.scrollToPosition(0);
mustScrollToPosition = false;
}
goToTodayEnabler.validateGoToTodayButton(upcomingEventsListView);
hideLoading();
showData();
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,4 @@ void displayUpcomingEvents(List<UpcomingRowViewModel> upcomingEventRows, OnUpcom
notifyDataSetChanged();
}

int getClosestDayPosition() {
// the first item in the list is always the closest one to the today date
return 0;
}
}
Loading