-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created Dialog for Adding Tags (#74)
* created TagFragment * made addTagButton final * Created and applied util function for adding a chip to a chip group * more consolidation and updated tag colours to resemble mockup * removed unused imports * updated Javadocs * cleaned up a few more things
- Loading branch information
1 parent
f720b03
commit 4981f1f
Showing
5 changed files
with
171 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/example/househomey/tags/TagFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.example.househomey.tags; | ||
|
||
import android.app.AlertDialog; | ||
import android.app.Dialog; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
|
||
import androidx.fragment.app.DialogFragment; | ||
|
||
import com.example.househomey.R; | ||
import com.example.househomey.utils.FragmentUtils; | ||
import com.google.android.material.chip.Chip; | ||
import com.google.android.material.chip.ChipGroup; | ||
|
||
/** | ||
* DialogFragment that allows users to add new tags | ||
* @author Matthew Neufeld | ||
*/ | ||
public class TagFragment extends DialogFragment { | ||
|
||
// Declare UI components | ||
private ChipGroup chipGroup; | ||
private EditText tagEditText; | ||
private Button addTagButton; | ||
private Chip chip; | ||
|
||
/** | ||
* Called to create the dialog, initializing UI components and setting up button listeners. | ||
* | ||
* @param savedInstanceState Bundle containing the saved state of the fragment. | ||
* @return The created AlertDialog. | ||
*/ | ||
@Override | ||
public Dialog onCreateDialog(Bundle savedInstanceState) { | ||
|
||
// Initialize AlertDialog builder | ||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); | ||
|
||
// Inflate the layout for this fragment | ||
LayoutInflater inflater = requireActivity().getLayoutInflater(); | ||
View rootView = inflater.inflate(R.layout.fragment_tags, null); | ||
|
||
// Initialize UI components | ||
chipGroup = rootView.findViewById(R.id.chip_group_labels); | ||
tagEditText = rootView.findViewById(R.id.tag_edit_text); | ||
addTagButton = rootView.findViewById(R.id.add_tag_button); | ||
|
||
// Set up button click listener to add tags | ||
addTagButton.setOnClickListener(v -> { | ||
String tagLabel = tagEditText.getText().toString().trim(); | ||
if (!tagLabel.isEmpty()) | ||
addTag(tagLabel); | ||
}); | ||
|
||
return builder | ||
.setView(rootView) | ||
.setTitle("Tags") | ||
.setNeutralButton("Cancel", null) | ||
.setPositiveButton("Apply Tags", null) | ||
.create(); | ||
} | ||
|
||
/** | ||
* Adds a new tag to the ChipGroup when addTagButton is clicked. | ||
* @param tagLabel the label that will go on the tag | ||
*/ | ||
private void addTag(String tagLabel) { | ||
chip = FragmentUtils.makeChip(tagLabel, false, chipGroup, requireContext(), R.color.white, R.color.black, R.color.black); | ||
chip.setOnCloseIconClickListener(v -> chipGroup.removeView(chip)); // for deleting tags - leave for now - we will discuss what we want to do | ||
tagEditText.getText().clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:padding="16dp"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal"> | ||
|
||
<com.google.android.material.textfield.TextInputLayout | ||
style="@style/TextInputLayoutStyle" | ||
android:layout_width="0dp" | ||
android:layout_weight="1" | ||
android:layout_height="wrap_content" | ||
android:hint="New tag" | ||
app:hintEnabled="true"> | ||
<com.google.android.material.textfield.TextInputEditText | ||
android:id="@+id/tag_edit_text" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:inputType="text"/> | ||
</com.google.android.material.textfield.TextInputLayout> | ||
|
||
<com.google.android.material.button.MaterialButton | ||
android:id="@+id/add_tag_button" | ||
style="?android:attr/borderlessButtonStyle" | ||
android:layout_width="30dp" | ||
android:layout_height="30dp" | ||
android:padding="0dp" | ||
android:layout_marginRight="8dp" | ||
android:layout_marginLeft="8dp" | ||
app:icon="@drawable/baseline_add_24" | ||
app:iconSize="30dp" | ||
app:iconTint="@color/black" /> | ||
</LinearLayout> | ||
|
||
<com.google.android.material.chip.ChipGroup | ||
android:id="@+id/chip_group_labels" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:singleLine="false"> | ||
</com.google.android.material.chip.ChipGroup> | ||
|
||
</LinearLayout> |