From 54988dd51efd7b546cc6492e1a9efa551157d117 Mon Sep 17 00:00:00 2001 From: zwicki Date: Mon, 14 Jun 2021 22:24:51 +0200 Subject: [PATCH 1/2] dynamic content update --- .../Teraplex/AddButtonDialogSingle.java | 40 ++++++++----------- .../de/jg_cody/Teraplex/MainActivity.java | 7 +--- .../Teraplex/ui/Flur/FlurFragment.java | 12 ++++-- .../Teraplex/ui/rooms/ListAdapter.java | 30 +++++++++----- .../jg_cody/Teraplex/ui/rooms/ListItem.java | 10 +---- .../Teraplex/ui/rooms/ListItemDouble.java | 5 +++ .../Teraplex/ui/rooms/ListItemSingle.java | 18 ++++++++- app/src/main/res/layout/doublebutton.xml | 9 ++--- app/src/main/res/layout/singlebutton.xml | 4 +- 9 files changed, 75 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/de/jg_cody/Teraplex/AddButtonDialogSingle.java b/app/src/main/java/de/jg_cody/Teraplex/AddButtonDialogSingle.java index 9436d5c..422088f 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/AddButtonDialogSingle.java +++ b/app/src/main/java/de/jg_cody/Teraplex/AddButtonDialogSingle.java @@ -8,16 +8,18 @@ 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.rooms.ListItem; +import de.jg_cody.Teraplex.ui.rooms.*; public class AddButtonDialogSingle extends DialogFragment { - private EditText editTextUsername; - private EditText editTextPassword; - - private EditText command, name, button_name; + private EditText editText_command, editText_name, editText_button_name; private AddButtonDialogListener listener; /** @@ -31,9 +33,9 @@ public class AddButtonDialogSingle extends DialogFragment { LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.addbuttondialog_single, null); - command = getActivity().findViewById(R.id.dialogSingle_editText_command); - name = getActivity().findViewById(R.id.dialogSingle_editText_name); - button_name = getActivity().findViewById(R.id.dialogSingle_editText_buttonName); + editText_command = getActivity().findViewById(R.id.dialogSingle_editText_command); + editText_name = getActivity().findViewById(R.id.dialogSingle_editText_name); + editText_button_name = getActivity().findViewById(R.id.dialogSingle_editText_buttonName); builder.setView(view) @@ -47,9 +49,11 @@ public class AddButtonDialogSingle extends DialogFragment { .setPositiveButton("ADD", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - String username = editTextUsername.getText().toString(); - String password = editTextPassword.getText().toString(); - listener.applyTexts(username, password); + String command = editText_command.getText().toString(); + String name = editText_name.getText().toString(); + String button = editText_button_name.getText().toString(); + listener.applyTexts(name,command,button); + } }); @@ -73,19 +77,9 @@ public class AddButtonDialogSingle extends DialogFragment { public interface AddButtonDialogListener { - void applyTexts(String username, String password); + void applyTexts(String name, String command, String button); } - public String getName() - { - return name.getText().toString(); - } - public String getButtonName() - { - return button_name.getText().toString(); - } - public String getCommand() - { - return command.getText().toString(); - } + + } \ No newline at end of file diff --git a/app/src/main/java/de/jg_cody/Teraplex/MainActivity.java b/app/src/main/java/de/jg_cody/Teraplex/MainActivity.java index 6f5feff..4e74bb5 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/MainActivity.java +++ b/app/src/main/java/de/jg_cody/Teraplex/MainActivity.java @@ -53,7 +53,7 @@ import de.jg_cody.Teraplex.ui.Konsole.KonsoleFragment; import de.jg_cody.Teraplex.ui.home.HomeFragment; -public class MainActivity extends AppCompatActivity implements AddButtonDialogSingle.AddButtonDialogListener { +public class MainActivity extends AppCompatActivity { public static int RESULT_LOAD_IMAGE = 0; private AppBarConfiguration mAppBarConfiguration; @@ -186,11 +186,6 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialogSi - @Override - public void applyTexts(String username, String password) { - - } - public void menurighttopeinstellungen(MenuItem i) { EinstellungenFragment pef = new EinstellungenFragment(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); diff --git a/app/src/main/java/de/jg_cody/Teraplex/ui/Flur/FlurFragment.java b/app/src/main/java/de/jg_cody/Teraplex/ui/Flur/FlurFragment.java index b9c7b69..335cd6d 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/ui/Flur/FlurFragment.java +++ b/app/src/main/java/de/jg_cody/Teraplex/ui/Flur/FlurFragment.java @@ -32,7 +32,7 @@ import de.jg_cody.Teraplex.MainActivity; import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.ui.rooms.*; -public class FlurFragment extends Fragment{ +public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddButtonDialogListener{ private FlurViewModel flurViewModel; @@ -113,9 +113,6 @@ public class FlurFragment extends Fragment{ public void openDialog1() { AddButtonDialogSingle addButtonDialogSingle = new AddButtonDialogSingle(); addButtonDialogSingle.show(getActivity().getSupportFragmentManager(), "example dialog"); - items.add(new ListItemSingle(addButtonDialogSingle.getCommand(),1, addButtonDialogSingle.getName(), addButtonDialogSingle.getButtonName())); - listAdapter.notifyDataSetChanged(); - } @@ -128,4 +125,11 @@ public class FlurFragment extends Fragment{ public void addItems(View v) { listAdapter.notifyDataSetChanged(); } + + @Override + public void applyTexts(String name, String command, String button) { + items.add(new ListItemSingle(1,name,command,button)); + listAdapter.notifyDataSetChanged(); + + } } \ No newline at end of file diff --git a/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListAdapter.java b/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListAdapter.java index df008bc..669b5f1 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListAdapter.java +++ b/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListAdapter.java @@ -10,7 +10,6 @@ import android.widget.Button; import java.util.ArrayList; import de.jg_cody.Teraplex.R; -import de.jg_cody.Teraplex.ui.Flur.FlurFragment; public class ListAdapter extends ArrayAdapter { @@ -44,29 +43,38 @@ public class ListAdapter extends ArrayAdapter { ListItem listViewItem = objects.get(position); int listViewItemType = getItemViewType(position); - + String[] s = listViewItem.getStrings(); if (convertView == null) { if (listViewItemType == SINGLEBUTTON) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.singlebutton, null); - Button bRun = convertView.findViewById(R.id.bRun); - Button text = convertView.findViewById(R.id.TEXT); - bRun.setText(listViewItem.getText()); + Button bRun = convertView.findViewById(R.id.singleButton_button); + Button text = convertView.findViewById(R.id.singleButton_text); + + bRun.setText(s[2]); + text.setText(s[0]); //text.setText(listViewItemType.get) - viewHolder = new ViewHolderSingleButton(bRun , listViewItem.getText()); - convertView.setTag(viewHolder); + //viewHolder = new ViewHolderSingleButton(bRun , listViewItem.getText()); + //convertView.setTag(viewHolder); } else if (listViewItemType == DOUBLEBUTTON) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.doublebutton, null); - Button bLeft = (Button) convertView.findViewById(R.id.bLeft); - Button bRight = (Button) convertView.findViewById(R.id.bRight); + Button bLeft = (Button) convertView.findViewById(R.id.doubleButton_bLeft); + Button bRight = (Button) convertView.findViewById(R.id.doubleButton_bRight); + Button text = (Button) convertView.findViewById(R.id.doubleButton_text); - viewHolder = new ViewHolderDoubleButton(bLeft,bRight,listViewItem.getText()); + bLeft.setText(s[3]); + bRight.setText(s[4]); + text.setText(s[0]); - convertView.setTag(viewHolder); + + + //viewHolder = new ViewHolderDoubleButton(bLeft,bRight,listViewItem.getText()); + + //convertView.setTag(viewHolder); } else if(listViewItemType == OPTION3BUTTON) diff --git a/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListItem.java b/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListItem.java index 2e96c22..94e365f 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListItem.java +++ b/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListItem.java @@ -1,6 +1,6 @@ package de.jg_cody.Teraplex.ui.rooms; -public class ListItem { +public abstract class ListItem { private String text; private int type; @@ -10,13 +10,7 @@ public class ListItem { - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } + abstract public String[] getStrings(); public int getType() { return type; diff --git a/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListItemDouble.java b/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListItemDouble.java index 065e550..77c62a4 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListItemDouble.java +++ b/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListItemDouble.java @@ -52,4 +52,9 @@ public class ListItemDouble extends ListItem{ return button2; } + @Override + public String[] getStrings() { + String[] s = {name, command1, command2, button1,button2}; + return s; + } } diff --git a/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListItemSingle.java b/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListItemSingle.java index 3fc5a30..618615c 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListItemSingle.java +++ b/app/src/main/java/de/jg_cody/Teraplex/ui/rooms/ListItemSingle.java @@ -2,12 +2,14 @@ package de.jg_cody.Teraplex.ui.rooms; public class ListItemSingle extends ListItem{ String buttonName; + String command; String name; - public ListItemSingle(String command, int type, String buttonName, String name) { + public ListItemSingle(int type, String name,String command,String buttonName ) { super(type); this.name = name; this.buttonName = buttonName; + this.command = command; } public void setButtonName(String buttonName) @@ -26,4 +28,18 @@ public class ListItemSingle extends ListItem{ { return name; } + public void setCommand(String command) + { + this.command = command; + } + public String getCommand() + { + return command; + } + + @Override + public String[] getStrings() { + String[] s = {name, command, buttonName}; + return s; + } } diff --git a/app/src/main/res/layout/doublebutton.xml b/app/src/main/res/layout/doublebutton.xml index d7f4548..7c317dc 100644 --- a/app/src/main/res/layout/doublebutton.xml +++ b/app/src/main/res/layout/doublebutton.xml @@ -9,7 +9,7 @@