removing tabs is now working perfectly
This commit is contained in:
parent
e765794fd7
commit
6433e841f3
@ -50,6 +50,7 @@ import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -58,11 +59,10 @@ import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import de.jg_cody.Teraplex.ui.Credits.CreditsFragment;
|
||||
import de.jg_cody.Teraplex.ui.Einstellungen.EinstellungenFragment;
|
||||
@ -81,6 +81,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
ListView listView;
|
||||
EditText editText_name;
|
||||
ArrayList<ListItem> items;
|
||||
int lastID = 6969;
|
||||
|
||||
Map<String, MenuItem> tabitems = new HashMap<>();
|
||||
|
||||
@ -194,7 +195,18 @@ public class MainActivity extends AppCompatActivity {
|
||||
String tabname = editText_name.getText().toString().trim();
|
||||
|
||||
SharedPreferences p = getSharedPreferences("appsettings", MODE_PRIVATE);
|
||||
Set<String> tabs = new HashSet<>(p.getStringSet("tabs", new HashSet<>()));
|
||||
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();
|
||||
}
|
||||
}
|
||||
if(tabs.contains(tabname) ) {
|
||||
MediaPlayer mp = MediaPlayer.create(MainActivity.this, R.raw.state_change_confirm_up);
|
||||
mp.start();
|
||||
@ -227,7 +239,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
mDialog.show();
|
||||
return;
|
||||
}
|
||||
MenuItem item = navigationView.getMenu().add(R.id.dynamicgroup, Menu.NONE, 3, tabname);
|
||||
MenuItem item = navigationView.getMenu().add(R.id.dynamicgroup, lastID++, 3, tabname);
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
@ -250,7 +262,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
tabs.add(tabname);
|
||||
SharedPreferences.Editor editor = p.edit();
|
||||
editor.putStringSet("tabs", tabs);
|
||||
editor.putString("tabs", new JSONArray(tabs).toString());
|
||||
editor.apply();
|
||||
|
||||
}
|
||||
@ -278,8 +290,19 @@ public class MainActivity extends AppCompatActivity {
|
||||
assert vr != null;
|
||||
vr.vibrate(100);
|
||||
SharedPreferences p = getSharedPreferences("appsettings", MODE_PRIVATE);
|
||||
Set<String> tabs = new HashSet<>(p.getStringSet("tabs", new HashSet<>()));
|
||||
Set<String> selectedTabs = new HashSet<>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
List<String> selectedTabs = new ArrayList<>();
|
||||
String[] tabsarray = tabs.toArray(new String[0]);
|
||||
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
|
||||
mBuilder.setTitle(R.string.menu_remove);
|
||||
@ -304,13 +327,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
vr.vibrate(100);
|
||||
tabs.removeAll(selectedTabs);
|
||||
SharedPreferences.Editor editor = p.edit();
|
||||
editor.putStringSet("tabs", tabs);
|
||||
editor.putString("tabs", new JSONArray(tabs).toString());
|
||||
for (String tab : selectedTabs) {
|
||||
editor.remove("listItems." + tab);
|
||||
editor.apply();
|
||||
navigationView.getMenu().removeItem(tabitems.get(tab).getItemId());
|
||||
tabitems.remove(tab);
|
||||
dialogInterface.dismiss();
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -329,9 +353,20 @@ public class MainActivity extends AppCompatActivity {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
Set<String> tabs = new HashSet<>(p.getStringSet("tabs", new HashSet<>()));
|
||||
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();
|
||||
}
|
||||
}
|
||||
for (String tab : tabs) {
|
||||
MenuItem item = navigationView.getMenu().add(R.id.dynamicgroup, Menu.NONE, 3, tab);
|
||||
MenuItem item = navigationView.getMenu().add(R.id.dynamicgroup, lastID++, 3, tab);
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
|
Loading…
Reference in New Issue
Block a user