Adds AdvantagePicker and ProficiencyPicker components.
This commit is contained in:
		| @@ -0,0 +1,98 @@ | |||||||
|  | package com.majinnaibu.monstercards.ui.components; | ||||||
|  |  | ||||||
|  | import android.content.Context; | ||||||
|  | import android.util.AttributeSet; | ||||||
|  | import android.view.LayoutInflater; | ||||||
|  | import android.view.View; | ||||||
|  | import android.widget.RadioGroup; | ||||||
|  |  | ||||||
|  | import androidx.annotation.NonNull; | ||||||
|  | import androidx.annotation.Nullable; | ||||||
|  | import androidx.constraintlayout.widget.ConstraintLayout; | ||||||
|  |  | ||||||
|  | import com.google.android.material.radiobutton.MaterialRadioButton; | ||||||
|  | import com.majinnaibu.monstercards.R; | ||||||
|  | import com.majinnaibu.monstercards.data.enums.AdvantageType; | ||||||
|  |  | ||||||
|  | @SuppressWarnings("unused") | ||||||
|  | public class AdvantagePicker extends ConstraintLayout { | ||||||
|  |     private final ViewHolder mHolder; | ||||||
|  |     private OnValueChangedListener mOnValueChangedListener; | ||||||
|  |     private AdvantageType mSelectedValue; | ||||||
|  |  | ||||||
|  |     public AdvantagePicker(@NonNull Context context, @Nullable AttributeSet attrs) { | ||||||
|  |         super(context, attrs); | ||||||
|  |  | ||||||
|  |         mSelectedValue = AdvantageType.NONE; | ||||||
|  |         mOnValueChangedListener = null; | ||||||
|  |  | ||||||
|  |         LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | ||||||
|  |         View root = inflater.inflate(R.layout.component_advantage_picker, this, true); | ||||||
|  |  | ||||||
|  |         mHolder = new ViewHolder(root); | ||||||
|  |  | ||||||
|  |         setValue(AdvantageType.NONE); | ||||||
|  |         mHolder.group.setOnCheckedChangeListener((group, checkedId) -> { | ||||||
|  |             if (R.id.advantage == checkedId) { | ||||||
|  |                 setValue(AdvantageType.ADVANTAGE); | ||||||
|  |             } else if (R.id.disadvantage == checkedId) { | ||||||
|  |                 setValue(AdvantageType.DISADVANTAGE); | ||||||
|  |             } else { | ||||||
|  |                 setValue(AdvantageType.NONE); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public AdvantagePicker(@NonNull Context context) { | ||||||
|  |         this(context, null); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public AdvantageType getValue() { | ||||||
|  |         return mSelectedValue; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void setValue(AdvantageType value) { | ||||||
|  |         if (mSelectedValue != value) { | ||||||
|  |             mSelectedValue = value; | ||||||
|  |             if (mOnValueChangedListener != null) { | ||||||
|  |                 mOnValueChangedListener.onValueChanged(mSelectedValue); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         final int checkedId = mHolder.group.getCheckedRadioButtonId(); | ||||||
|  |         if (mSelectedValue == AdvantageType.ADVANTAGE) { | ||||||
|  |             if (checkedId != R.id.advantage) { | ||||||
|  |                 mHolder.advantage.setChecked(true); | ||||||
|  |             } | ||||||
|  |         } else if (mSelectedValue == AdvantageType.DISADVANTAGE) { | ||||||
|  |             if (checkedId != R.id.disadvantage) { | ||||||
|  |                 mHolder.disadvantage.setChecked(true); | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             if (checkedId != R.id.none) { | ||||||
|  |                 mHolder.none.setChecked(true); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void setOnValueChangedListener(OnValueChangedListener listener) { | ||||||
|  |         mOnValueChangedListener = listener; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public interface OnValueChangedListener { | ||||||
|  |         void onValueChanged(AdvantageType value); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private static class ViewHolder { | ||||||
|  |         final RadioGroup group; | ||||||
|  |         final MaterialRadioButton none; | ||||||
|  |         final MaterialRadioButton advantage; | ||||||
|  |         final MaterialRadioButton disadvantage; | ||||||
|  |  | ||||||
|  |         ViewHolder(View root) { | ||||||
|  |             group = root.findViewById(R.id.group); | ||||||
|  |             none = root.findViewById(R.id.none); | ||||||
|  |             advantage = root.findViewById(R.id.advantage); | ||||||
|  |             disadvantage = root.findViewById(R.id.disadvantage); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,98 @@ | |||||||
|  | package com.majinnaibu.monstercards.ui.components; | ||||||
|  |  | ||||||
|  | import android.content.Context; | ||||||
|  | import android.util.AttributeSet; | ||||||
|  | import android.view.LayoutInflater; | ||||||
|  | import android.view.View; | ||||||
|  | import android.widget.RadioGroup; | ||||||
|  |  | ||||||
|  | import androidx.annotation.NonNull; | ||||||
|  | import androidx.annotation.Nullable; | ||||||
|  | import androidx.constraintlayout.widget.ConstraintLayout; | ||||||
|  |  | ||||||
|  | import com.google.android.material.radiobutton.MaterialRadioButton; | ||||||
|  | import com.majinnaibu.monstercards.R; | ||||||
|  | import com.majinnaibu.monstercards.data.enums.ProficiencyType; | ||||||
|  |  | ||||||
|  | @SuppressWarnings("unused") | ||||||
|  | public class ProficiencyPicker extends ConstraintLayout { | ||||||
|  |     private final ViewHolder mHolder; | ||||||
|  |     private OnValueChangedListener mOnValueChangedListener; | ||||||
|  |     private ProficiencyType mSelectedValue; | ||||||
|  |  | ||||||
|  |     public ProficiencyPicker(@NonNull Context context, @Nullable AttributeSet attrs) { | ||||||
|  |         super(context, attrs); | ||||||
|  |  | ||||||
|  |         mSelectedValue = ProficiencyType.NONE; | ||||||
|  |         mOnValueChangedListener = null; | ||||||
|  |  | ||||||
|  |         LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | ||||||
|  |         View root = inflater.inflate(R.layout.component_proficiency_picker, this, true); | ||||||
|  |  | ||||||
|  |         mHolder = new ViewHolder(root); | ||||||
|  |  | ||||||
|  |         setValue(ProficiencyType.NONE); | ||||||
|  |         mHolder.group.setOnCheckedChangeListener((group, checkedId) -> { | ||||||
|  |             if (R.id.proficient == checkedId) { | ||||||
|  |                 setValue(ProficiencyType.PROFICIENT); | ||||||
|  |             } else if (R.id.expertise == checkedId) { | ||||||
|  |                 setValue(ProficiencyType.EXPERTISE); | ||||||
|  |             } else { | ||||||
|  |                 setValue(ProficiencyType.NONE); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ProficiencyPicker(@NonNull Context context) { | ||||||
|  |         this(context, null); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ProficiencyType getValue() { | ||||||
|  |         return mSelectedValue; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void setValue(ProficiencyType value) { | ||||||
|  |         if (mSelectedValue != value) { | ||||||
|  |             mSelectedValue = value; | ||||||
|  |             if (mOnValueChangedListener != null) { | ||||||
|  |                 mOnValueChangedListener.onValueChanged(mSelectedValue); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         final int checkedId = mHolder.group.getCheckedRadioButtonId(); | ||||||
|  |         if (mSelectedValue == ProficiencyType.PROFICIENT) { | ||||||
|  |             if (checkedId != R.id.proficient) { | ||||||
|  |                 mHolder.proficient.setChecked(true); | ||||||
|  |             } | ||||||
|  |         } else if (mSelectedValue == ProficiencyType.EXPERTISE) { | ||||||
|  |             if (checkedId != R.id.expertise) { | ||||||
|  |                 mHolder.expertise.setChecked(true); | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             if (checkedId != R.id.none) { | ||||||
|  |                 mHolder.none.setChecked(true); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public void setOnValueChangedListener(OnValueChangedListener listener) { | ||||||
|  |         mOnValueChangedListener = listener; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public interface OnValueChangedListener { | ||||||
|  |         void onValueChanged(ProficiencyType value); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private static class ViewHolder { | ||||||
|  |         final RadioGroup group; | ||||||
|  |         final MaterialRadioButton none; | ||||||
|  |         final MaterialRadioButton proficient; | ||||||
|  |         final MaterialRadioButton expertise; | ||||||
|  |  | ||||||
|  |         ViewHolder(View root) { | ||||||
|  |             group = root.findViewById(R.id.group); | ||||||
|  |             none = root.findViewById(R.id.none); | ||||||
|  |             proficient = root.findViewById(R.id.proficient); | ||||||
|  |             expertise = root.findViewById(R.id.expertise); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										48
									
								
								app/src/main/res/layout/component_advantage_picker.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								app/src/main/res/layout/component_advantage_picker.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <merge xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||||
|  |     xmlns:tools="http://schemas.android.com/tools" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="wrap_content" | ||||||
|  |     android:layout_margin="@dimen/text_margin" | ||||||
|  |     tools:context=".ui.components.AdvantagePicker"> | ||||||
|  |  | ||||||
|  |     <TextView | ||||||
|  |         android:id="@+id/label" | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:text="@string/label_advantage" | ||||||
|  |         app:layout_constraintStart_toStartOf="parent" | ||||||
|  |         app:layout_constraintTop_toTopOf="parent" | ||||||
|  |         tools:text="Proficiency" /> | ||||||
|  |  | ||||||
|  |     <RadioGroup | ||||||
|  |         android:id="@+id/group" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:orientation="horizontal" | ||||||
|  |         app:layout_constraintBottom_toBottomOf="parent" | ||||||
|  |         app:layout_constraintTop_toBottomOf="@id/label"> | ||||||
|  |  | ||||||
|  |         <com.google.android.material.radiobutton.MaterialRadioButton | ||||||
|  |             android:id="@+id/none" | ||||||
|  |             android:layout_width="0dp" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:text="@string/label_advantage_none" /> | ||||||
|  |  | ||||||
|  |         <com.google.android.material.radiobutton.MaterialRadioButton | ||||||
|  |             android:id="@+id/advantage" | ||||||
|  |             android:layout_width="0dp" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:text="@string/label_advantage_advantage" /> | ||||||
|  |  | ||||||
|  |         <com.google.android.material.radiobutton.MaterialRadioButton | ||||||
|  |             android:id="@+id/disadvantage" | ||||||
|  |             android:layout_width="0dp" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:text="@string/label_advantage_disadvantage" /> | ||||||
|  |     </RadioGroup> | ||||||
|  | </merge> | ||||||
							
								
								
									
										48
									
								
								app/src/main/res/layout/component_proficiency_picker.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								app/src/main/res/layout/component_proficiency_picker.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <merge xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||||
|  |     xmlns:tools="http://schemas.android.com/tools" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_height="wrap_content" | ||||||
|  |     android:layout_margin="@dimen/text_margin" | ||||||
|  |     tools:context=".ui.components.ProficiencyPicker"> | ||||||
|  |  | ||||||
|  |     <TextView | ||||||
|  |         android:id="@+id/label" | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:text="@string/label_proficiency" | ||||||
|  |         app:layout_constraintStart_toStartOf="parent" | ||||||
|  |         app:layout_constraintTop_toTopOf="parent" | ||||||
|  |         tools:text="Proficiency" /> | ||||||
|  |  | ||||||
|  |     <RadioGroup | ||||||
|  |         android:id="@+id/group" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:orientation="horizontal" | ||||||
|  |         app:layout_constraintBottom_toBottomOf="parent" | ||||||
|  |         app:layout_constraintTop_toBottomOf="@id/label"> | ||||||
|  |  | ||||||
|  |         <com.google.android.material.radiobutton.MaterialRadioButton | ||||||
|  |             android:id="@+id/none" | ||||||
|  |             android:layout_width="0dp" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:text="@string/label_proficiency_none" /> | ||||||
|  |  | ||||||
|  |         <com.google.android.material.radiobutton.MaterialRadioButton | ||||||
|  |             android:id="@+id/proficient" | ||||||
|  |             android:layout_width="0dp" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:text="@string/label_proficiency_proficient" /> | ||||||
|  |  | ||||||
|  |         <com.google.android.material.radiobutton.MaterialRadioButton | ||||||
|  |             android:id="@+id/expertise" | ||||||
|  |             android:layout_width="0dp" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:text="@string/label_proficiency_expertise" /> | ||||||
|  |     </RadioGroup> | ||||||
|  | </merge> | ||||||
| @@ -12,6 +12,10 @@ | |||||||
|     <string name="label_ability_scores">Ability Scores</string> |     <string name="label_ability_scores">Ability Scores</string> | ||||||
|     <string name="label_abilities">Abilities</string> |     <string name="label_abilities">Abilities</string> | ||||||
|     <string name="label_actions">Actions</string> |     <string name="label_actions">Actions</string> | ||||||
|  |     <string name="label_advantage">Advantage</string> | ||||||
|  |     <string name="label_advantage_advantage">Advantage</string> | ||||||
|  |     <string name="label_advantage_disadvantage">Disadvantage</string> | ||||||
|  |     <string name="label_advantage_none">None</string> | ||||||
|     <string name="label_alignment">Alignment</string> |     <string name="label_alignment">Alignment</string> | ||||||
|     <string name="label_armor">Armor</string> |     <string name="label_armor">Armor</string> | ||||||
|     <string name="label_base_speed">Base Speed</string> |     <string name="label_base_speed">Base Speed</string> | ||||||
| @@ -42,6 +46,10 @@ | |||||||
|     <string name="label_legendary_actions">Legendary Actions</string> |     <string name="label_legendary_actions">Legendary Actions</string> | ||||||
|     <string name="label_natural_armor_bonus">Natural Armor Bonus</string> |     <string name="label_natural_armor_bonus">Natural Armor Bonus</string> | ||||||
|     <string name="label_name">Name</string> |     <string name="label_name">Name</string> | ||||||
|  |     <string name="label_proficiency">Proficiency</string> | ||||||
|  |     <string name="label_proficiency_expertise">Expertise</string> | ||||||
|  |     <string name="label_proficiency_none">None</string> | ||||||
|  |     <string name="label_proficiency_proficient">Proficient</string> | ||||||
|     <string name="label_reactions">Reactions</string> |     <string name="label_reactions">Reactions</string> | ||||||
|     <string name="label_regional_actions">Regional Actions</string> |     <string name="label_regional_actions">Regional Actions</string> | ||||||
|     <string name="label_saving_throws">Saving Throws</string> |     <string name="label_saving_throws">Saving Throws</string> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user