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..05015b2 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/AddButtonDialogSingle.java +++ b/app/src/main/java/de/jg_cody/Teraplex/AddButtonDialogSingle.java @@ -1,6 +1,7 @@ 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; @@ -8,17 +9,21 @@ 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 editTextUsername; - private EditText editTextPassword; - - private EditText command, name, button_name; - private AddButtonDialogListener listener; + private EditText editText_command, editText_name, editText_button_name; + private AddButtonDialogListenerSingle listener; + private FlurFragment frag; /** * @@ -31,9 +36,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 = view.findViewById(R.id.dialogSingle_editText_command); + editText_name = view.findViewById(R.id.dialogSingle_editText_name); + editText_button_name = view.findViewById(R.id.dialogSingle_editText_buttonName); builder.setView(view) @@ -47,9 +52,10 @@ 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.applyTextsSingle(name,command,button); } }); @@ -59,33 +65,33 @@ public class AddButtonDialogSingle extends DialogFragment { 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 = (AddButtonDialogListener) context; - } catch (ClassCastException e) { - throw new ClassCastException(context.toString() + + try { + listener = (AddButtonDialogListenerSingle) frag; + } catch (ClassCastException e) { + throw new ClassCastException(frag.toString() + "must implement ExampleDialogListener"); + } } + + + + public interface AddButtonDialogListenerSingle { + void applyTextsSingle(String name, String command, String button); } - public interface AddButtonDialogListener { - void applyTexts(String username, String password); - } - 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/AddButtonsDialogDouble.java b/app/src/main/java/de/jg_cody/Teraplex/AddButtonsDialogDouble.java index c7e1490..8d29800 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/AddButtonsDialogDouble.java +++ b/app/src/main/java/de/jg_cody/Teraplex/AddButtonsDialogDouble.java @@ -11,11 +11,14 @@ import android.widget.EditText; import androidx.fragment.app.DialogFragment; +import de.jg_cody.Teraplex.ui.Flur.FlurFragment; + public class AddButtonsDialogDouble extends DialogFragment { - private AddButtonsDialogListener listener; + private AddButtonsDialogListenerDouble listener; private EditText name, command1, button1, command2, button2; + private FlurFragment frag; @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @@ -44,44 +47,33 @@ public class AddButtonsDialogDouble extends DialogFragment { command2 = getActivity().findViewById(R.id.dialogDouble_editText_command2); button1 = getActivity().findViewById(R.id.dialogDouble_editText_button1); button2 = getActivity().findViewById(R.id.dialogDouble_editText_button2); + 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 = (AddButtonsDialogListener) context; + listener = (AddButtonsDialogListenerDouble) frag; } catch (ClassCastException e) { } } - public interface AddButtonsDialogListener { - void applyTexts(String username, String password); + public interface AddButtonsDialogListenerDouble { + void applyTextsDouble(String name, String command1, String command2, String button1, String button2); } +} - public String getName() - { - return name.getText().toString(); - } - public String getCommand1() - { - return command1.getText().toString(); - } - public String getButton1() - { - return button1.getText().toString(); - } - public String getCommand2() - { - return command2.getText().toString(); - } - public String getButton2() - { - return button2.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..9a13b2c 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/MainActivity.java +++ b/app/src/main/java/de/jg_cody/Teraplex/MainActivity.java @@ -1,7 +1,9 @@ package de.jg_cody.Teraplex; import android.app.Activity; +import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; @@ -27,6 +29,7 @@ import android.view.MenuItem; import android.view.View; import android.view.WindowManager; import android.widget.ImageView; +import android.widget.ListView; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; @@ -44,19 +47,30 @@ import com.google.android.material.navigation.NavigationView; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.Base64; import java.util.Locale; +import java.util.Objects; import de.jg_cody.Teraplex.ui.Credits.CreditsFragment; import de.jg_cody.Teraplex.ui.Einstellungen.EinstellungenFragment; import de.jg_cody.Teraplex.ui.Konsole.KonsoleFragment; import de.jg_cody.Teraplex.ui.home.HomeFragment; +import de.jg_cody.Teraplex.ui.rooms.ListAdapter; +import de.jg_cody.Teraplex.ui.rooms.ListItem; +import de.jg_cody.Teraplex.ui.rooms.ListItemDouble; +import de.jg_cody.Teraplex.ui.rooms.ListItemSingle; -public class MainActivity extends AppCompatActivity implements AddButtonDialogSingle.AddButtonDialogListener { +public class MainActivity extends AppCompatActivity { public static int RESULT_LOAD_IMAGE = 0; private AppBarConfiguration mAppBarConfiguration; + ListAdapter listAdapter; + ListView listView; + + ArrayList items; + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override protected void onCreate(Bundle savedInstanceState) { @@ -132,9 +146,19 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialogSi NavigationUI.setupWithNavController(navigationView, navController); + + + + + + + + } + + /*static public class DemoPreferenceFragment extends PreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { @@ -186,11 +210,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(); @@ -313,4 +332,6 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialogSi canvas.drawRect(0F, 0F, (float) width, (float) height, paint); return bitmap; } + + } 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 6fd2ad7..b9c7b69 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 @@ -1,12 +1,17 @@ package de.jg_cody.Teraplex.ui.Flur; +import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.graphics.BitmapFactory; +import android.graphics.drawable.BitmapDrawable; import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.ListView; import androidx.annotation.NonNull; @@ -17,16 +22,15 @@ import androidx.lifecycle.ViewModelProvider; import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.util.ArrayList; +import java.util.Base64; import java.util.Objects; import de.jg_cody.Teraplex.AddButtonDialogSingle; import de.jg_cody.Teraplex.AddButtonsDialogDouble; 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.ListAdapter; -import de.jg_cody.Teraplex.ui.rooms.ListItem; -import de.jg_cody.Teraplex.ui.rooms.ListItemDouble; -import de.jg_cody.Teraplex.ui.rooms.ListItemSingle; +import de.jg_cody.Teraplex.ui.rooms.*; public class FlurFragment extends Fragment{ @@ -49,14 +53,14 @@ public class FlurFragment extends Fragment{ flurViewModel = new ViewModelProvider(this).get(FlurViewModel.class); View root = inflater.inflate(R.layout.fragment_flur, container, false); -/* SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE); + SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE); String Background = p.getString("Background", null); if (Background != null) { ImageView I = root.findViewById(R.id.Background); byte[] BA = Base64.getDecoder().decode(Background); I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth()))); I.setScaleType(ImageView.ScaleType.CENTER_CROP); - } */ + } @@ -108,7 +112,7 @@ public class FlurFragment extends Fragment{ } public void openDialog1() { AddButtonDialogSingle addButtonDialogSingle = new AddButtonDialogSingle(); - addButtonDialogSingle.show(requireActivity().getSupportFragmentManager(), "example dialog"); + addButtonDialogSingle.show(getActivity().getSupportFragmentManager(), "example dialog"); items.add(new ListItemSingle(addButtonDialogSingle.getCommand(),1, addButtonDialogSingle.getName(), addButtonDialogSingle.getButtonName())); listAdapter.notifyDataSetChanged(); @@ -117,7 +121,7 @@ public class FlurFragment extends Fragment{ public void openDialog2() { AddButtonsDialogDouble addButtonsDialogDouble = new AddButtonsDialogDouble(); - addButtonsDialogDouble.show(requireActivity().getSupportFragmentManager(), "example dialog"); + addButtonsDialogDouble.show(getActivity().getSupportFragmentManager(), "example dialog"); items.add(new ListItemDouble(2,addButtonsDialogDouble.getName(), addButtonsDialogDouble.getCommand1(), addButtonsDialogDouble.getCommand2(), addButtonsDialogDouble.getButton1(), addButtonsDialogDouble.getButton2())); listAdapter.notifyDataSetChanged(); } 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 660fa01..d9499a6 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 @@ -48,29 +48,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); } } 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 @@