added headline to dynamic content

This commit is contained in:
JG-Cody 2021-06-28 18:17:58 +02:00
parent 80b1beb09d
commit e1b9a30648
9 changed files with 142 additions and 55 deletions

View File

@ -1,7 +1,6 @@
package de.jg_cody.Teraplex;
import android.app.Dialog;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
@ -9,16 +8,11 @@ import android.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import androidx.fragment.app.DialogFragment;
import java.util.ArrayList;
import de.jg_cody.Teraplex.ui.Flur.FlurFragment;
import de.jg_cody.Teraplex.ui.rooms.ListItem;
import de.jg_cody.Teraplex.ui.rooms.*;
public class AddButtonDialogSingle extends DialogFragment {
private EditText editText_command, editText_name, editText_button_name;
@ -37,7 +31,7 @@ public class AddButtonDialogSingle extends DialogFragment {
View view = inflater.inflate(R.layout.addbuttondialog_single, null);
editText_command = view.findViewById(R.id.dialogSingle_editText_command);
editText_name = view.findViewById(R.id.dialogSingle_editText_name);
editText_name = view.findViewById(R.id.dialogheadline_editText_name);
editText_button_name = view.findViewById(R.id.dialogSingle_editText_buttonName);

View File

@ -0,0 +1,80 @@
package de.jg_cody.Teraplex;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import androidx.fragment.app.DialogFragment;
import de.jg_cody.Teraplex.ui.Flur.FlurFragment;
public class AddHeadlineDialog extends DialogFragment {
private AddHeadlineDialogListener listener;
private EditText editText_name;
private FlurFragment frag;
/**
*
* @param savedInstanceState
* @return
*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.addheadlinedialog, null);
editText_name = view.findViewById(R.id.dialogheadline_editText_name);
builder.setView(view)
.setTitle("SINGLE BUTTON")
.setNegativeButton("CANCEL", (dialogInterface, i) -> {
})
.setPositiveButton("ADD", (dialogInterface, i) -> {
String headline = editText_name.getText().toString();
listener.applyTextsHeadline(headline);
});
AlertDialog mDialog = builder.create();
mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round);
return mDialog;
}
public void setFragment(FlurFragment frag)
{
this.frag = frag;
}
public FlurFragment getFragment()
{
return frag;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
listener = (AddHeadlineDialogListener) frag;
} catch (ClassCastException e) {
throw new ClassCastException(frag.toString() +
"must implement ExampleDialogListener");
}
}
public interface AddHeadlineDialogListener {
void applyTextsHeadline(String headline);
}
}

View File

@ -27,12 +27,13 @@ import java.util.Objects;
import de.jg_cody.Teraplex.AddButtonDialogSingle;
import de.jg_cody.Teraplex.AddButtonsDialogDouble;
import de.jg_cody.Teraplex.AddHeadlineDialog;
import de.jg_cody.Teraplex.Cricketer;
import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R;
import de.jg_cody.Teraplex.ui.rooms.*;
public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddButtonDialogListenerSingle, AddButtonsDialogDouble.AddButtonsDialogListenerDouble {
public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddButtonDialogListenerSingle, AddButtonsDialogDouble.AddButtonsDialogListenerDouble, AddHeadlineDialog.AddHeadlineDialogListener {
private FlurViewModel flurViewModel;
@ -100,7 +101,7 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
} else if (i == 1) {
openDialog2();
} else if (i == 2) {
openDialog3();
} else if (i == 3) {
listAdapter.add(new ListItemSpace(3));
listAdapter.notifyDataSetChanged();
@ -129,6 +130,12 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
addButtonsDialogDouble.setFragment(this);
addButtonsDialogDouble.show(getActivity().getSupportFragmentManager(), "example dialog");
}
public void openDialog3() {
list_item_type = 2;
AddHeadlineDialog addHeadlineDialog = new AddHeadlineDialog();
addHeadlineDialog.setFragment(this);
addHeadlineDialog.show(getActivity().getSupportFragmentManager(), "Headline");
}
@Override
public void applyTextsSingle(String name, String command, String button) {
@ -143,4 +150,11 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
listAdapter.add(new ListItemDouble(list_item_type,name, command1, command2, button1, button2));
listAdapter.notifyDataSetChanged();
}
@Override
public void applyTextsHeadline(String headline) {
listAdapter.add(new ListItemHeadline(list_item_type,headline));
listAdapter.notifyDataSetChanged();
}
}

View File

@ -83,6 +83,11 @@ public class ListAdapter extends ArrayAdapter {
} else if (listViewItemType == SPACE) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.space, null);
}else if (listViewItemType == HEADLINE) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.headline, null);
Button text = (Button) convertView.findViewById(R.id.headline_text);
text.setText(s[0]);
} else {
viewHolder = (IViewHolder) convertView.getTag();
}

View File

@ -2,8 +2,8 @@ package de.jg_cody.Teraplex.ui.rooms;
public class ListItemHeadline extends ListItem{
private String name, command1, command2,button1, button2;
public ListItemHeadline(int type, String name, String command1, String command2, String button1, String button2) {
private String name;
public ListItemHeadline(int type, String name) {
super( type);
this.name = name;
}
@ -11,46 +11,16 @@ public class ListItemHeadline extends ListItem{
{
this.name = name;
}
public void setCommand1(String command1)
{
this.command1 = command1;
}
public void setCommand2(String command2)
{
this.command2 = command2;
}
public void setButton1(String button1)
{
this.button1 = button1;
}
public void setButton2(String button2)
{
this.button2 = button2;
}
public String getName()
{
return name;
}
public String getCommand1()
{
return command1;
}
public String getCommand2()
{
return command2;
}
public String getButton1()
{
return button1;
}
public String getButton2()
{
return button2;
}
@Override
public String[] getStrings() {
String[] s = {name, command1, command2, button1,button2};
String[] s = {name};
return s;
}
}

View File

@ -5,24 +5,26 @@ import android.widget.Button;
import android.widget.Toast;
public class ViewHolderDoubleButton implements IViewHolder{
String command;
String commandL;
String commandR;
Button bLeft, bRight;
public ViewHolderDoubleButton(Button bLeft, Button bRight, String command) {
public ViewHolderDoubleButton(Button bLeft, Button bRight, String commandL, String commandR) {
this.bLeft = bLeft;
this.bRight = bRight;
this.command = command;
this.commandL = commandL;
this.commandR = commandR;
bLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(bLeft.getContext(),command + " ON",Toast.LENGTH_SHORT).show();
Toast.makeText(bLeft.getContext(),commandL + " ON",Toast.LENGTH_SHORT).show();
}
});
bRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(bRight.getContext(),command + " ON",Toast.LENGTH_SHORT).show();
Toast.makeText(bRight.getContext(),commandR + " OFF",Toast.LENGTH_SHORT).show();
}
});
@ -30,7 +32,7 @@ public class ViewHolderDoubleButton implements IViewHolder{
}
@Override
public String getCommand() {
return command;
return commandL;
}
public Button getbLeft() {
return bLeft;

View File

@ -6,7 +6,7 @@
android:orientation="vertical" >
<EditText
android:id="@+id/dialogSingle_editText_name"
android:id="@+id/dialogheadline_editText_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:orientation="vertical" >
<EditText
android:id="@+id/dialogheadline_editText_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
</LinearLayout>

View File

@ -6,10 +6,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
<Button
android:id="@+id/headline_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:text="TextView" />
android:background="@drawable/button_round"
android:insetLeft="25dp"
android:insetRight="25dp"
android:text="TEXT"
app:backgroundTint="@null" />
</LinearLayout>