Added TypePanel ui elements to EditDialog

pull/419/head
Jake Powell 7 years ago
parent f7bebf0b3a
commit 98d09e6d55

@ -0,0 +1,88 @@
/*
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.activities.habits.edit.views;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.Spinner;
import android.widget.TextView;
import org.isoron.uhabits.R;
import org.isoron.uhabits.core.models.Frequency;
import org.isoron.uhabits.core.models.Habit;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnItemSelected;
import static org.isoron.uhabits.R.id.numerator;
public class TypePanel extends FrameLayout
{
@BindView(R.id.spinner)
Spinner spinner;
public TypePanel(@NonNull Context context,
@Nullable AttributeSet attrs)
{
super(context, attrs);
View view = inflate(context, R.layout.edit_habit_type, null);
ButterKnife.bind(this, view);
addView(view);
}
@NonNull
public Integer getType()
{
Integer type = spinner.getSelectedItemPosition();
if (type.equals(0)) return Habit.YES_NO_HABIT;
if (type.equals(0)) return Habit.NUMBER_HABIT;
return -1;
}
public void setType(@NonNull Integer type)
{
int position = getQuickSelectPosition(type);
spinner.setSelection(position);
}
@OnItemSelected(R.id.spinner)
public void onTypeSelected(int position)
{
if (position < 0 || position > 1) throw new IllegalArgumentException();
// TODO: A callback?
}
private int getQuickSelectPosition(@NonNull Integer type)
{
if (type.equals(Habit.YES_NO_HABIT)) return 0;
if (type.equals(Habit.NUMBER_HABIT)) return 1;
return -1;
}
}

@ -34,6 +34,11 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
<org.isoron.uhabits.activities.habits.edit.views.TypePanel
android:id="@+id/typePanel"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<org.isoron.uhabits.activities.habits.edit.views.FrequencyPanel <org.isoron.uhabits.activities.habits.edit.views.FrequencyPanel
android:id="@+id/frequencyPanel" android:id="@+id/frequencyPanel"
android:layout_width="match_parent" android:layout_width="match_parent"

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
~
~ This file is part of Loop Habit Tracker.
~
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by the
~ Free Software Foundation, either version 3 of the License, or (at your
~ option) any later version.
~
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout style="@style/dialogFormRow"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:orientation="horizontal">
<TextView
style="@style/dialogFormLabel"
android:text="@string/type"/>
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:entries="@array/habitTypes"
android:minWidth="400dp"
android:theme="@style/dialogFormText"/>
</LinearLayout>

@ -80,7 +80,7 @@
</string-array> </string-array>
<string-array name="habitTypes" translatable="false"> <string-array name="habitTypes" translatable="false">
<item>Yes or No</item> <item>Checked/Unchecked</item>
<item>Number</item> <item>Number</item>
</string-array> </string-array>

@ -45,6 +45,7 @@
<string name="history">History</string> <string name="history">History</string>
<string name="clear">Clear</string> <string name="clear">Clear</string>
<string name="description_hint">Question (Did you … today?)</string> <string name="description_hint">Question (Did you … today?)</string>
<string name="type">Type</string>
<string name="repeat">Repeat</string> <string name="repeat">Repeat</string>
<string name="times_every">times in</string> <string name="times_every">times in</string>
<string name="days">days</string> <string name="days">days</string>

Loading…
Cancel
Save