diff --git a/NOTICE.md b/NOTICE.md index 12368d1e6..cea565a0b 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -89,3 +89,22 @@ Material design icons are the official icon set from Google that are designed under the material design guidelines. Available under the Creative Common Attribution 4.0 International License (CC-BY 4.0). +### Android Flow Layout + + + +Extended linear layout that wrap its content when there is no place in the current line. + + Copyright 2011, Artem Votincev (apmem.org) + + Licensed under the Apache License, Version 2.0 (the "License"); you may not + use this file except in compliance with the License. You may obtain a copy + of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + License for the specific language governing permissions and limitations + under the License. \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 9f90fd1ab..2921e8b81 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,6 +34,7 @@ android { dependencies { compile 'com.android.support:support-v4:23.1.1' compile 'com.github.paolorotolo:appintro:3.4.0' + compile 'org.apmem.tools:layouts:1.10@aar' compile project(':libs:drag-sort-listview:library') compile files('libs/ActiveAndroid.jar') diff --git a/app/src/androidTest/java/org/isoron/uhabits/ui/MainActivityActions.java b/app/src/androidTest/java/org/isoron/uhabits/ui/MainActivityActions.java index 412bee5f9..40699aa35 100644 --- a/app/src/androidTest/java/org/isoron/uhabits/ui/MainActivityActions.java +++ b/app/src/androidTest/java/org/isoron/uhabits/ui/MainActivityActions.java @@ -19,7 +19,7 @@ package org.isoron.uhabits.ui; -import android.support.test.espresso.matcher.ViewMatchers; +import android.support.test.espresso.NoMatchingViewException; import org.isoron.uhabits.R; import org.isoron.uhabits.models.Habit; @@ -37,14 +37,18 @@ 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.replaceText; import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.RootMatchers.isPlatformPopup; +import static android.support.test.espresso.matcher.ViewMatchers.Visibility.VISIBLE; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription; +import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.startsWith; import static org.isoron.uhabits.ui.HabitMatchers.containsHabit; import static org.isoron.uhabits.ui.HabitMatchers.withName; @@ -97,6 +101,20 @@ public class MainActivityActions .perform(replaceText(name)); onView(withId(R.id.input_description)) .perform(replaceText(description)); + + try + { + onView(allOf(withId(R.id.sFrequency), withEffectiveVisibility(VISIBLE))) + .perform(click()); + onData(allOf(instanceOf(String.class), startsWith("Custom"))) + .inRoot(isPlatformPopup()) + .perform(click()); + } + catch(NoMatchingViewException e) + { + // ignored + } + onView(withId(R.id.input_freq_num)) .perform(replaceText(num)); onView(withId(R.id.input_freq_den)) diff --git a/app/src/main/java/org/isoron/uhabits/fragments/EditHabitFragment.java b/app/src/main/java/org/isoron/uhabits/fragments/EditHabitFragment.java index 75b93cd8c..54fba7430 100644 --- a/app/src/main/java/org/isoron/uhabits/fragments/EditHabitFragment.java +++ b/app/src/main/java/org/isoron/uhabits/fragments/EditHabitFragment.java @@ -19,9 +19,9 @@ package org.isoron.uhabits.fragments; +import android.annotation.SuppressLint; import android.app.DialogFragment; import android.content.SharedPreferences; -import android.graphics.Color; import android.os.Bundle; import android.preference.PreferenceManager; import android.text.format.DateFormat; @@ -29,8 +29,11 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.Button; import android.widget.ImageButton; +import android.widget.LinearLayout; +import android.widget.Spinner; import android.widget.TextView; import com.android.colorpicker.ColorPickerDialog; @@ -49,11 +52,10 @@ import org.isoron.uhabits.dialogs.WeekdayPickerDialog; import org.isoron.uhabits.models.Habit; import java.util.Arrays; -import java.util.Date; public class EditHabitFragment extends DialogFragment implements OnClickListener, WeekdayPickerDialog.OnWeekdaysPickedListener, - TimePickerDialog.OnTimeSetListener + TimePickerDialog.OnTimeSetListener, Spinner.OnItemSelectedListener { private Integer mode; static final int EDIT_MODE = 0; @@ -71,6 +73,10 @@ public class EditHabitFragment extends DialogFragment private TextView tvReminderTime; private TextView tvReminderDays; + private Spinner sFrequency; + private ViewGroup llCustomFrequency; + private ViewGroup llReminderDays; + private SharedPreferences prefs; private boolean is24HourMode; @@ -105,6 +111,10 @@ public class EditHabitFragment extends DialogFragment tvReminderTime = (TextView) view.findViewById(R.id.inputReminderTime); tvReminderDays = (TextView) view.findViewById(R.id.inputReminderDays); + sFrequency = (Spinner) view.findViewById(R.id.sFrequency); + llCustomFrequency = (ViewGroup) view.findViewById(R.id.llCustomFrequency); + llReminderDays = (ViewGroup) view.findViewById(R.id.llReminderDays); + Button buttonSave = (Button) view.findViewById(R.id.buttonSave); Button buttonDiscard = (Button) view.findViewById(R.id.buttonDiscard); ImageButton buttonPickColor = (ImageButton) view.findViewById(R.id.buttonPickColor); @@ -114,6 +124,7 @@ public class EditHabitFragment extends DialogFragment tvReminderTime.setOnClickListener(this); tvReminderDays.setOnClickListener(this); buttonPickColor.setOnClickListener(this); + sFrequency.setOnItemSelectedListener(this); prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); @@ -163,6 +174,7 @@ public class EditHabitFragment extends DialogFragment tvFreqDen.append(modifiedHabit.freqDen.toString()); changeColor(modifiedHabit.color); + updateFrequency(); updateReminder(); return view; @@ -183,19 +195,17 @@ public class EditHabitFragment extends DialogFragment { if (modifiedHabit.hasReminder()) { - tvReminderTime.setTextColor(Color.BLACK); tvReminderTime.setText(DateHelper.formatTime(getActivity(), modifiedHabit.reminderHour, modifiedHabit.reminderMin)); - tvReminderDays.setVisibility(View.VISIBLE); + llReminderDays.setVisibility(View.VISIBLE); boolean weekdays[] = DateHelper.unpackWeekdayList(modifiedHabit.reminderDays); tvReminderDays.setText(DateHelper.formatWeekdayList(getActivity(), weekdays)); } else { - tvReminderTime.setTextColor(Color.GRAY); tvReminderTime.setText(R.string.reminder_off); - tvReminderDays.setVisibility(View.GONE); + llReminderDays.setVisibility(View.GONE); } } @@ -378,4 +388,79 @@ public class EditHabitFragment extends DialogFragment outState.putInt("reminderDays", modifiedHabit.reminderDays); } } + + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) + { + if(parent.getId() == R.id.sFrequency) + { + switch (position) + { + case 0: + modifiedHabit.freqNum = 1; + modifiedHabit.freqDen = 1; + break; + + case 1: + modifiedHabit.freqNum = 1; + modifiedHabit.freqDen = 7; + break; + + case 2: + modifiedHabit.freqNum = 2; + modifiedHabit.freqDen = 7; + break; + + case 3: + modifiedHabit.freqNum = 5; + modifiedHabit.freqDen = 7; + break; + + case 4: + modifiedHabit.freqNum = 3; + modifiedHabit.freqDen = 7; + break; + } + } + + updateFrequency(); + } + + @SuppressLint("SetTextI18n") + private void updateFrequency() + { + int quickSelectPosition = -1; + + if(modifiedHabit.freqNum.equals(modifiedHabit.freqDen)) + quickSelectPosition = 0; + + else if(modifiedHabit.freqNum == 1 && modifiedHabit.freqDen == 7) + quickSelectPosition = 1; + + else if(modifiedHabit.freqNum == 2 && modifiedHabit.freqDen == 7) + quickSelectPosition = 2; + + else if(modifiedHabit.freqNum == 5 && modifiedHabit.freqDen == 7) + quickSelectPosition = 3; + + if(quickSelectPosition >= 0) + { + sFrequency.setVisibility(View.VISIBLE); + sFrequency.setSelection(quickSelectPosition); + llCustomFrequency.setVisibility(View.GONE); + tvFreqNum.setText(modifiedHabit.freqNum.toString()); + tvFreqDen.setText(modifiedHabit.freqDen.toString()); + } + else + { + sFrequency.setVisibility(View.GONE); + llCustomFrequency.setVisibility(View.VISIBLE); + } + } + + @Override + public void onNothingSelected(AdapterView parent) + { + + } } diff --git a/app/src/main/res/layout/edit_habit.xml b/app/src/main/res/layout/edit_habit.xml index 4d4dd8218..493dc1c67 100644 --- a/app/src/main/res/layout/edit_habit.xml +++ b/app/src/main/res/layout/edit_habit.xml @@ -17,12 +17,13 @@ ~ with this program. If not, see . --> - + tools:ignore="MergeRootFrame"> + style="@style/dialogFormInput" + android:hint="@string/name"> - + + android:src="@drawable/ic_action_color_light"/> + style="@style/dialogFormInputMultiline" + android:hint="@string/description_hint"/> + style="@style/dialogFormRow"> - - + android:text="@string/repeat"/> - - - + android:entries="@array/frequencyQuickSelect" + android:visibility="gone"/> - + android:visibility="visible" + android:gravity="fill"> + + + + + + + + + + + android:text="@string/reminder"/> + style="@style/dialogFormSpinner"/> + + + + + + style="@style/dialogFormSpinner"/> @@ -110,20 +136,22 @@ android:layout_height="wrap_content" android:gravity="end" android:paddingEnd="16dp" - android:paddingRight="16dp"> + android:paddingLeft="0dp" + android:paddingRight="16dp" + android:paddingStart="0dp">