dynamic content update

This commit is contained in:
zwicki 2021-06-27 16:27:09 +02:00
parent 9ecb6b17c3
commit af360901a1
5 changed files with 87 additions and 48 deletions

View File

@ -1,6 +1,7 @@
package de.jg_cody.Teraplex; package de.jg_cody.Teraplex;
import android.app.Dialog; import android.app.Dialog;
import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
@ -15,12 +16,14 @@ import androidx.fragment.app.DialogFragment;
import java.util.ArrayList; 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.ListItem;
import de.jg_cody.Teraplex.ui.rooms.*; import de.jg_cody.Teraplex.ui.rooms.*;
public class AddButtonDialogSingle extends DialogFragment { public class AddButtonDialogSingle extends DialogFragment {
private EditText editText_command, editText_name, editText_button_name; private EditText editText_command, editText_name, editText_button_name;
private AddButtonDialogListener listener; private AddButtonDialogListenerSingle listener;
private FlurFragment frag;
/** /**
* *
@ -33,9 +36,9 @@ public class AddButtonDialogSingle extends DialogFragment {
LayoutInflater inflater = getActivity().getLayoutInflater(); LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.addbuttondialog_single, null); View view = inflater.inflate(R.layout.addbuttondialog_single, null);
editText_command = getActivity().findViewById(R.id.dialogSingle_editText_command); editText_command = view.findViewById(R.id.dialogSingle_editText_command);
editText_name = getActivity().findViewById(R.id.dialogSingle_editText_name); editText_name = view.findViewById(R.id.dialogSingle_editText_name);
editText_button_name = getActivity().findViewById(R.id.dialogSingle_editText_buttonName); editText_button_name = view.findViewById(R.id.dialogSingle_editText_buttonName);
builder.setView(view) builder.setView(view)
@ -52,8 +55,7 @@ public class AddButtonDialogSingle extends DialogFragment {
String command = editText_command.getText().toString(); String command = editText_command.getText().toString();
String name = editText_name.getText().toString(); String name = editText_name.getText().toString();
String button = editText_button_name.getText().toString(); String button = editText_button_name.getText().toString();
listener.applyTexts(name,command,button); listener.applyTextsSingle(name,command,button);
} }
}); });
@ -63,21 +65,31 @@ public class AddButtonDialogSingle extends DialogFragment {
return mDialog; return mDialog;
} }
public void setFragment(FlurFragment frag)
{
this.frag = frag;
}
public FlurFragment getFragment()
{
return frag;
}
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
try { try {
listener = (AddButtonDialogListener) context; listener = (AddButtonDialogListenerSingle) frag;
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new ClassCastException(context.toString() + throw new ClassCastException(frag.toString() +
"must implement ExampleDialogListener"); "must implement ExampleDialogListener");
}
} }
}
public interface AddButtonDialogListener {
void applyTexts(String name, String command, String button); public interface AddButtonDialogListenerSingle {
void applyTextsSingle(String name, String command, String button);
} }

View File

@ -11,11 +11,14 @@ import android.widget.EditText;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import de.jg_cody.Teraplex.ui.Flur.FlurFragment;
public class AddButtonsDialogDouble extends DialogFragment { public class AddButtonsDialogDouble extends DialogFragment {
private AddButtonsDialogListener listener; private AddButtonsDialogListenerDouble listener;
private EditText name, command1, button1, command2, button2; private EditText name, command1, button1, command2, button2;
private FlurFragment frag;
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
@ -44,44 +47,33 @@ public class AddButtonsDialogDouble extends DialogFragment {
command2 = getActivity().findViewById(R.id.dialogDouble_editText_command2); command2 = getActivity().findViewById(R.id.dialogDouble_editText_command2);
button1 = getActivity().findViewById(R.id.dialogDouble_editText_button1); button1 = getActivity().findViewById(R.id.dialogDouble_editText_button1);
button2 = getActivity().findViewById(R.id.dialogDouble_editText_button2); button2 = getActivity().findViewById(R.id.dialogDouble_editText_button2);
AlertDialog mDialog = builder.create(); AlertDialog mDialog = builder.create();
mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round); mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round);
return mDialog; return mDialog;
} }
public void setFragment(FlurFragment frag) {
this.frag = frag;
}
public FlurFragment getFragment() {
return frag;
}
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
try { try {
listener = (AddButtonsDialogListener) context; listener = (AddButtonsDialogListenerDouble) frag;
} catch (ClassCastException e) { } catch (ClassCastException e) {
} }
} }
public interface AddButtonsDialogListener { public interface AddButtonsDialogListenerDouble {
void applyTexts(String username, String password); 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();
}
}

View File

@ -1,7 +1,9 @@
package de.jg_cody.Teraplex; package de.jg_cody.Teraplex;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
@ -27,6 +29,7 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -44,19 +47,30 @@ import com.google.android.material.navigation.NavigationView;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import de.jg_cody.Teraplex.ui.Credits.CreditsFragment; import de.jg_cody.Teraplex.ui.Credits.CreditsFragment;
import de.jg_cody.Teraplex.ui.Einstellungen.EinstellungenFragment; import de.jg_cody.Teraplex.ui.Einstellungen.EinstellungenFragment;
import de.jg_cody.Teraplex.ui.Konsole.KonsoleFragment; import de.jg_cody.Teraplex.ui.Konsole.KonsoleFragment;
import de.jg_cody.Teraplex.ui.home.HomeFragment; 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 { public class MainActivity extends AppCompatActivity {
public static int RESULT_LOAD_IMAGE = 0; public static int RESULT_LOAD_IMAGE = 0;
private AppBarConfiguration mAppBarConfiguration; private AppBarConfiguration mAppBarConfiguration;
ListAdapter listAdapter;
ListView listView;
ArrayList<ListItem> items;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -132,9 +146,19 @@ public class MainActivity extends AppCompatActivity {
NavigationUI.setupWithNavController(navigationView, navController); NavigationUI.setupWithNavController(navigationView, navController);
} }
/*static public class DemoPreferenceFragment extends PreferenceFragmentCompat { /*static public class DemoPreferenceFragment extends PreferenceFragmentCompat {
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@ -308,4 +332,6 @@ public class MainActivity extends AppCompatActivity {
canvas.drawRect(0F, 0F, (float) width, (float) height, paint); canvas.drawRect(0F, 0F, (float) width, (float) height, paint);
return bitmap; return bitmap;
} }
} }

View File

@ -32,7 +32,7 @@ import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
import de.jg_cody.Teraplex.ui.rooms.*; import de.jg_cody.Teraplex.ui.rooms.*;
public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddButtonDialogListener{ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddButtonDialogListenerSingle, AddButtonsDialogDouble.AddButtonsDialogListenerDouble {
private FlurViewModel flurViewModel; private FlurViewModel flurViewModel;
@ -47,6 +47,8 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
ArrayList<Cricketer> cricketersList = new ArrayList<>(); ArrayList<Cricketer> cricketersList = new ArrayList<>();
int list_item_type;
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
@ -111,25 +113,31 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
mDialog.show(); mDialog.show();
} }
public void openDialog1() { public void openDialog1() {
list_item_type = 0;
AddButtonDialogSingle addButtonDialogSingle = new AddButtonDialogSingle(); AddButtonDialogSingle addButtonDialogSingle = new AddButtonDialogSingle();
addButtonDialogSingle.setFragment(this);
addButtonDialogSingle.show(getActivity().getSupportFragmentManager(), "example dialog"); addButtonDialogSingle.show(getActivity().getSupportFragmentManager(), "example dialog");
} }
public void openDialog2() { public void openDialog2() {
list_item_type = 1;
AddButtonsDialogDouble addButtonsDialogDouble = new AddButtonsDialogDouble(); AddButtonsDialogDouble addButtonsDialogDouble = new AddButtonsDialogDouble();
addButtonsDialogDouble.setFragment(this);
addButtonsDialogDouble.show(getActivity().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();
}
public void addItems(View v) {
listAdapter.notifyDataSetChanged();
} }
@Override @Override
public void applyTexts(String name, String command, String button) { public void applyTextsSingle(String name, String command, String button) {
items.add(new ListItemSingle(1,name,command,button)); //items.add(new ListItemSingle(0,name,command,button));
listAdapter.add(new ListItemSingle(list_item_type,name,command,button));
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} }
@Override
public void applyTextsDouble(String name, String command1, String command2, String button1, String button2) {
listAdapter.add(new ListItemDouble(list_item_type,name, command1, command2, button1, button2));
listAdapter.notifyDataSetChanged();
}
} }

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_flur"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity">
@ -19,8 +20,8 @@
<ListView <ListView
android:id="@+id/listView" android:id="@+id/listView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="742dp" android:layout_height="match_parent"
android:visibility="visible"/> android:visibility="visible" />
</FrameLayout> </FrameLayout>