Import & Export & EditMode
This commit is contained in:
parent
3961a880f1
commit
b915b860c8
@ -19,6 +19,7 @@ import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.SpannableString;
|
||||
@ -33,7 +34,6 @@ import android.view.WindowManager;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Switch;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@ -51,10 +51,16 @@ import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -64,21 +70,20 @@ import java.util.Objects;
|
||||
|
||||
import de.jg_cody.Teraplex.ui.credits.CreditsFragment;
|
||||
import de.jg_cody.Teraplex.ui.settings.SettingsFragment;
|
||||
import de.jg_cody.Teraplex.ui.tabs.ListAdapter;
|
||||
import de.jg_cody.Teraplex.ui.tabs.ListItem;
|
||||
import de.jg_cody.Teraplex.ui.tabs.TabsFragment;
|
||||
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
public static int RESULT_LOAD_IMAGE = 0;
|
||||
private AppBarConfiguration mAppBarConfiguration;
|
||||
// Request code for selecting a PDF document.
|
||||
public static final int PICK_PDF_FILE = 2;
|
||||
public static final int CREATE_FILE = 1;
|
||||
|
||||
public static boolean editmode = false;
|
||||
|
||||
ListAdapter listAdapter;
|
||||
ListView listView;
|
||||
|
||||
EditText editText_name;
|
||||
ArrayList<ListItem> items;
|
||||
int lastID = 6969;
|
||||
|
||||
Map<String, MenuItem> tabitems = new HashMap<>();
|
||||
@ -550,8 +555,78 @@ public class MainActivity extends AppCompatActivity {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (requestCode == CREATE_FILE && resultCode == RESULT_OK && null != data) {
|
||||
|
||||
data.getData();
|
||||
try {
|
||||
ParcelFileDescriptor pfd = getContentResolver().
|
||||
openFileDescriptor(data.getData(), "w");
|
||||
FileOutputStream fileOutputStream =
|
||||
new FileOutputStream(pfd.getFileDescriptor());
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
List<String> listTabs = getTabsFromPrefs();
|
||||
jsonObject.put("tabs", new JSONArray(listTabs));
|
||||
JSONObject jsonTabs = new JSONObject();
|
||||
SharedPreferences p = this.getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
|
||||
for (String tab : listTabs) {
|
||||
String listItems = p.getString("listItems." + tab, "[]");
|
||||
JSONArray listItems2 = new JSONArray(listItems);
|
||||
jsonTabs.put(tab, listItems2);
|
||||
}
|
||||
jsonObject.put("tabitems", jsonTabs);
|
||||
|
||||
fileOutputStream.write(jsonObject.toString().getBytes());
|
||||
// Let the document provider know you're done by closing the stream.
|
||||
fileOutputStream.close();
|
||||
pfd.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else if (requestCode == PICK_PDF_FILE && resultCode == RESULT_OK && null != data) {
|
||||
try {
|
||||
|
||||
|
||||
ParcelFileDescriptor pfd = getContentResolver().
|
||||
openFileDescriptor(data.getData(), "r");
|
||||
FileInputStream fileInputStream =
|
||||
new FileInputStream(pfd.getFileDescriptor());
|
||||
BufferedReader bf = new BufferedReader(new InputStreamReader(fileInputStream));
|
||||
String s = bf.readLine();
|
||||
JSONObject jso = new JSONObject(s);
|
||||
SharedPreferences p = this.getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
|
||||
JSONArray tabs = jso.getJSONArray("tabs");
|
||||
SharedPreferences.Editor sharedEditor = p.edit();
|
||||
sharedEditor.putString("tabs",tabs.toString());
|
||||
JSONObject tabitems = jso.getJSONObject("tabitems");
|
||||
|
||||
for (int i = 0; i < tabs.length(); i++) {
|
||||
String tab = tabs.getString(i);
|
||||
JSONArray tArray = tabitems.getJSONArray(tab);
|
||||
sharedEditor.putString("listItems." + tab,tArray.toString());
|
||||
|
||||
}
|
||||
sharedEditor.apply();
|
||||
startActivity(getIntent());
|
||||
finish();
|
||||
|
||||
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void loadBackground() {
|
||||
@ -598,5 +673,23 @@ public class MainActivity extends AppCompatActivity {
|
||||
return dest;
|
||||
}
|
||||
|
||||
//muss oben noch ausgebessert werden
|
||||
public List<String> getTabsFromPrefs() {
|
||||
SharedPreferences p = getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
|
||||
String tabsString = p.getString("tabs", null);
|
||||
List<String> tabs = new ArrayList<String>();
|
||||
if (tabsString != null) {
|
||||
try {
|
||||
JSONArray tabsArray = new JSONArray(tabsString);
|
||||
for (int i = 0; i < tabsArray.length(); i++) {
|
||||
tabs.add(tabsArray.getString(i));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return tabs;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class SettingsFragment extends Fragment {
|
||||
Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
assert vr != null;
|
||||
vr.vibrate(100);
|
||||
showExportDialog();
|
||||
createFile();
|
||||
}
|
||||
});
|
||||
Button Import = root.findViewById(R.id.button_import);
|
||||
@ -76,7 +76,8 @@ public class SettingsFragment extends Fragment {
|
||||
Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
assert vr != null;
|
||||
vr.vibrate(100);
|
||||
showImportDialog();
|
||||
//showImportDialog();
|
||||
openFile();
|
||||
}
|
||||
});
|
||||
Button Reset = root.findViewById(R.id.button_reset);
|
||||
@ -288,87 +289,37 @@ public class SettingsFragment extends Fragment {
|
||||
editor.putString("Language", lang);
|
||||
editor.apply();
|
||||
}
|
||||
private void showExportDialog() {
|
||||
final String[] listItems = {"EXPORT BACKGROUND", "EXPORT LANGUAGESETTINGS", "EXPORT THEMESETTINGS", "EXPORT TABS"};
|
||||
AlertDialog.Builder mBuilder = new AlertDialog.Builder(getContext());
|
||||
mBuilder.setTitle(getString(R.string.export_settings));
|
||||
mBuilder.setMultiChoiceItems(listItems, null, new DialogInterface.OnMultiChoiceClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i, boolean b) {
|
||||
Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
assert vr != null;
|
||||
vr.vibrate(100);
|
||||
if (i == 0) {
|
||||
|
||||
} else if (i == 1) {
|
||||
|
||||
} else if (i == 2) {
|
||||
|
||||
} else if (i == 3) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
mBuilder.setPositiveButton(getString(R.string.button_export), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
LayoutInflater inflater = requireActivity().getLayoutInflater();
|
||||
View view = inflater.inflate(R.layout.exportdialog, null);
|
||||
|
||||
editExportFile_name = view.findViewById(R.id.dialogexport_editText_name);
|
||||
|
||||
|
||||
builder.setView(view)
|
||||
.setTitle("SINGLE BUTTON")
|
||||
.setNegativeButton(getString(R.string.cancel), (dialogExport, r) -> {
|
||||
|
||||
})
|
||||
.setPositiveButton(R.string.button_export, (dialogExport, r) -> {
|
||||
String headline = editExportFile_name.getText().toString();
|
||||
if(headline.isEmpty()){
|
||||
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up);
|
||||
mp.start();
|
||||
AlertDialog mDialog = new AlertDialog.Builder(getContext())
|
||||
.setTitle(getString(R.string.invalid))
|
||||
.setMessage(getString(R.string.inputfields_cant_be_empty))
|
||||
|
||||
// Specifying a listener allows you to take an action before dismissing the dialog.
|
||||
// The dialog is automatically dismissed when a dialog button is clicked.
|
||||
.setPositiveButton(android.R.string.yes, null )
|
||||
.create();
|
||||
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
|
||||
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
|
||||
mDialog.show();
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
AlertDialog mDialog = builder.create();
|
||||
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
|
||||
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
|
||||
mDialog.show();
|
||||
}
|
||||
}
|
||||
);
|
||||
mBuilder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
|
||||
}
|
||||
});
|
||||
AlertDialog mDialog = mBuilder.create();
|
||||
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
|
||||
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
|
||||
mDialog.show();
|
||||
}
|
||||
private void showImportDialog() {
|
||||
Intent a = new Intent(
|
||||
Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
requireActivity().startActivityForResult(a, MainActivity.RESULT_LOAD_IMAGE);
|
||||
}
|
||||
|
||||
|
||||
private void createFile() {
|
||||
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("application/json");
|
||||
intent.putExtra(Intent.EXTRA_TITLE, "export.json");
|
||||
|
||||
// Optionally, specify a URI for the directory that should be opened in
|
||||
// the system file picker when your app creates the document.
|
||||
//intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri);
|
||||
|
||||
getActivity().startActivityForResult(intent, 1);
|
||||
}
|
||||
private void openFile() {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("application/json");
|
||||
|
||||
// Optionally, specify a URI for the file that should appear in the
|
||||
// system file picker when it loads.
|
||||
|
||||
|
||||
getActivity().startActivityForResult(intent, MainActivity.PICK_PDF_FILE);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -29,8 +29,7 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
|
||||
|
||||
private AddButtonsDialogDouble.AddButtonsDialogListenerDouble listener;
|
||||
private EditText editText_name, editText_command, editText_command1, editText_button1, editText_command2, editText_button2, editText_button_name;
|
||||
|
||||
ListAdapter listAdapter;
|
||||
private TabsFragment frag;
|
||||
|
||||
public static final int
|
||||
SINGLEBUTTON = 0,
|
||||
@ -198,6 +197,19 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
|
||||
|
||||
return;
|
||||
}
|
||||
ListItemSingle item_tmp = (ListItemSingle) item;
|
||||
item_tmp.setButtonName(button);
|
||||
item_tmp.setCommand(command);
|
||||
item_tmp.setName(name);
|
||||
notifyDataSetChanged();
|
||||
try {
|
||||
TabsFragment.save(tabname, context, ListAdapter.this);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
@ -241,9 +253,22 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
|
||||
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
|
||||
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
|
||||
mDialog.show();
|
||||
|
||||
return;
|
||||
}
|
||||
listener.applyTextsDouble(name, command1, command2, button1, button2);
|
||||
ListItemDouble item_tmp = (ListItemDouble) item;
|
||||
item_tmp.setButton1(button1);
|
||||
item_tmp.setButton2(button2);
|
||||
item_tmp.setCommand1(command1);
|
||||
item_tmp.setCommand2(command2);
|
||||
item_tmp.setName(name);
|
||||
notifyDataSetChanged();
|
||||
try {
|
||||
TabsFragment.save(tabname, context, ListAdapter.this);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@ -296,7 +321,14 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
|
||||
mDialog.show();
|
||||
return;
|
||||
}
|
||||
|
||||
ListItemHeadline item_tmp = (ListItemHeadline) item;
|
||||
item_tmp.setName(headline);
|
||||
notifyDataSetChanged();
|
||||
try {
|
||||
TabsFragment.save(tabname, context, ListAdapter.this);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -365,6 +397,4 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,13 @@ public class ListItemHeadline extends ListItem{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getStrings() {
|
||||
|
@ -13,6 +13,18 @@ public class ListItemSingle extends ListItem{
|
||||
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
public void setButtonName(String buttonName)
|
||||
{
|
||||
this.buttonName = buttonName;
|
||||
}
|
||||
public void setCommand(String command)
|
||||
{
|
||||
this.command = command;
|
||||
}
|
||||
@Override
|
||||
public String[] getStrings() {
|
||||
String[] s = {name, command, buttonName};
|
||||
|
@ -19,10 +19,6 @@
|
||||
<string name="action_logout">AUSLOGGEN</string>
|
||||
<string name="Welcome_to_your_HOMEAUTOMATION_APP">WILLKOMMEN BEI TERAPLEX</string>
|
||||
<string name="login">EINLOGGEN</string>
|
||||
<string name="wlan">WLAN</string>
|
||||
<string name="kodi">KODI</string>
|
||||
<string name="off">AUS</string>
|
||||
<string name="on">AN</string>
|
||||
<string name="console">KONSOLE</string>
|
||||
<string name="button_send_command">BEFEHL SENDEN</string>
|
||||
<string name="servercommands">SERVERBEFEHLE</string>
|
||||
@ -59,7 +55,7 @@
|
||||
<string name="cooperation">IN KOOPERATION MIT</string>
|
||||
<string name="menu_add">REGISTERKARTE HINZUFÜGEN</string>
|
||||
<string name="menu_remove">REGISTERKARTE ENTFERNEN</string>
|
||||
<string name="edit">BEARBEITEN</string>
|
||||
<string name="edit">BEARBEITUNGSMODUS</string>
|
||||
<string name="cancel">ABBRECHEN</string>
|
||||
<string name="invalid">UNGÜLTIGE EINGABE</string>
|
||||
<string name="tabname">TABNAME</string>
|
||||
@ -90,7 +86,7 @@
|
||||
<string name="add">HINZUFÜGEN</string>
|
||||
<string name="command1">BEFEHL 1</string>
|
||||
<string name="name">NAME</string>
|
||||
<string name="command2">BEFEHL 1</string>
|
||||
<string name="command2">BEFEHL 2</string>
|
||||
<string name="button">SCHALTFLÄCHE</string>
|
||||
<string name="button1">SCHALTFLÄCHE 1</string>
|
||||
<string name="button2">SCHALTFLÄCHE 2</string>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<string name="nav_header_subtitle">ANDROID.STUDIO@ANDROID.COM</string>
|
||||
<string name="action_logout">LOGOUT</string>
|
||||
<string name="ssh_remote">SSH-REMOTE</string>
|
||||
<string name="edit">EDIT</string>
|
||||
<string name="edit">EDITMODE</string>
|
||||
|
||||
//home
|
||||
<string name="Welcome_to_your_HOMEAUTOMATION_APP">WELCOME TO TERAPLEX</string>
|
||||
@ -15,10 +15,6 @@
|
||||
<string name="login_password">PASSWORD</string>
|
||||
<string name="login">LOGIN</string>
|
||||
<string name="logout">LOGOUT</string>
|
||||
<string name="wlan">WLAN</string>
|
||||
<string name="kodi">KODI</string>
|
||||
<string name="off">OFF</string>
|
||||
<string name="on">ON</string>
|
||||
<string name="please_login">PLEASE CONNECT TO YOUR SERVER</string>
|
||||
<string name="sie_sind_als_angemeldet">YOU ARE LOGGED IN ON {IP} AS {USERNAME}</string>
|
||||
<string name="felder_dürfen_nicht_leer_sein">INPUTFIELDS CANT BE EMPTY!</string>
|
||||
|
Loading…
Reference in New Issue
Block a user