mirror of
https://github.com/TimeCrafters/TimeCraftersConfigurationTool.git
synced 2025-12-16 21:42:35 +00:00
Added settings for: showing navigation labels, disabling launcher delay, and starting server at boot.
This commit is contained in:
@@ -15,6 +15,7 @@ import androidx.core.content.ContextCompat;
|
|||||||
|
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||||
|
|
||||||
|
import org.timecrafters.TimeCraftersConfigurationTool.backend.Backend;
|
||||||
import org.timecrafters.TimeCraftersConfigurationTool.dialogs.PermissionsRequestDialog;
|
import org.timecrafters.TimeCraftersConfigurationTool.dialogs.PermissionsRequestDialog;
|
||||||
|
|
||||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||||
@@ -23,6 +24,7 @@ public class LauncherActivity extends AppCompatActivity {
|
|||||||
private static final int REQUEST_WRITE_PERMISSION = 70;
|
private static final int REQUEST_WRITE_PERMISSION = 70;
|
||||||
private static final String TAG = "LauncherActivity";
|
private static final String TAG = "LauncherActivity";
|
||||||
private static final long timerDelay = 2_000;
|
private static final long timerDelay = 2_000;
|
||||||
|
private static final long timerQuickDelay = 250; // Give LauncherActivity enough time to do first paint
|
||||||
private static final long timerDelayAfterPermissionRequest = 500;
|
private static final long timerDelayAfterPermissionRequest = 500;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,7 +47,15 @@ public class LauncherActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (havePermissions()) {
|
if (havePermissions()) {
|
||||||
|
if (Backend.instance() == null) {
|
||||||
|
new Backend();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Backend.instance().getSettings().mobileDisableLauncherDelay) {
|
||||||
|
startTimer(timerQuickDelay);
|
||||||
|
} else {
|
||||||
startTimer(timerDelay);
|
startTimer(timerDelay);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
new PermissionsRequestDialog().show(getSupportFragmentManager(), null);
|
new PermissionsRequestDialog().show(getSupportFragmentManager(), null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.content.IntentFilter;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.navigation.NavController;
|
import androidx.navigation.NavController;
|
||||||
@@ -13,6 +14,7 @@ import androidx.navigation.ui.AppBarConfiguration;
|
|||||||
import androidx.navigation.ui.NavigationUI;
|
import androidx.navigation.ui.NavigationUI;
|
||||||
|
|
||||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||||
|
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
|
||||||
|
|
||||||
import org.timecrafters.TimeCraftersConfigurationTool.backend.Backend;
|
import org.timecrafters.TimeCraftersConfigurationTool.backend.Backend;
|
||||||
import org.timecrafters.TimeCraftersConfigurationTool.backend.TAC;
|
import org.timecrafters.TimeCraftersConfigurationTool.backend.TAC;
|
||||||
@@ -45,6 +47,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
Backend.instance().applicationContext = getApplicationContext();
|
Backend.instance().applicationContext = getApplicationContext();
|
||||||
|
|
||||||
|
if (Backend.instance().getSettings().mobileShowNavigationLabels) {
|
||||||
|
navView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
|
||||||
|
}
|
||||||
|
|
||||||
// Auto start TACNET server if allowed and device model contains AUTO_START_MODEL
|
// Auto start TACNET server if allowed and device model contains AUTO_START_MODEL
|
||||||
if (TAC.allowAutoServerStart() && Backend.instance().getServer() == null) {
|
if (TAC.allowAutoServerStart() && Backend.instance().getServer() == null) {
|
||||||
Log.i(TAG, "Detected " + Build.MANUFACTURER + " " + Build.MODEL + " (" + Build.HARDWARE + "), starting TACNET Server Service...");
|
Log.i(TAG, "Detected " + Build.MANUFACTURER + " " + Build.MODEL + " (" + Build.HARDWARE + "), starting TACNET Server Service...");
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ public class Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeDefaultSettings() {
|
public void writeDefaultSettings() {
|
||||||
settings = new Settings(TACNET.DEFAULT_HOSTNAME, TACNET.DEFAULT_PORT, "");
|
settings = new Settings(TACNET.DEFAULT_HOSTNAME, TACNET.DEFAULT_PORT, "", false, false, false);
|
||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,16 @@ package org.timecrafters.TimeCraftersConfigurationTool.backend;
|
|||||||
public class Settings {
|
public class Settings {
|
||||||
public String hostname, config;
|
public String hostname, config;
|
||||||
public int port;
|
public int port;
|
||||||
|
public boolean mobileShowNavigationLabels, mobileDisableLauncherDelay, mobileStartServerAtBoot;
|
||||||
|
|
||||||
public Settings(String hostname, int port, String config) {
|
public Settings(String hostname, int port, String config, boolean mobileShowNavigationLabels,
|
||||||
|
boolean mobileDisableLauncherDelay, boolean mobileStartServerAtBoot) {
|
||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
|
this.mobileShowNavigationLabels = mobileShowNavigationLabels;
|
||||||
|
this.mobileDisableLauncherDelay = mobileDisableLauncherDelay;
|
||||||
|
this.mobileStartServerAtBoot = mobileStartServerAtBoot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ public class TAC {
|
|||||||
|
|
||||||
static public boolean allowAutoServerStart() {
|
static public boolean allowAutoServerStart() {
|
||||||
return !TAC.BUILD_COMPETITION_MODE &&
|
return !TAC.BUILD_COMPETITION_MODE &&
|
||||||
TAC.BUILD_AUTO_START &&
|
((TAC.BUILD_AUTO_START &&
|
||||||
Build.MODEL.toLowerCase().contains(TAC.BUILD_AUTO_START_MODEL);
|
Build.MODEL.toLowerCase().contains(TAC.BUILD_AUTO_START_MODEL)) ||
|
||||||
|
(Backend.instance() != null && Backend.instance().getSettings().mobileStartServerAtBoot));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,25 @@ public class SettingsDeserializer implements JsonDeserializer<Settings> {
|
|||||||
JsonObject jsonObject = json.getAsJsonObject();
|
JsonObject jsonObject = json.getAsJsonObject();
|
||||||
JsonObject data = jsonObject.get("data").getAsJsonObject();
|
JsonObject data = jsonObject.get("data").getAsJsonObject();
|
||||||
|
|
||||||
|
/* Upgrade Settings */
|
||||||
|
if (data.get("mobile_show_navigation_labels") == null) {
|
||||||
|
data.addProperty("mobile_show_navigation_labels", false);
|
||||||
|
}
|
||||||
|
if (data.get("mobile_disable_launcher_delay") == null) {
|
||||||
|
data.addProperty("mobile_disable_launcher_delay", false);
|
||||||
|
}
|
||||||
|
if (data.get("mobile_start_server_at_boot") == null) {
|
||||||
|
data.addProperty("mobile_start_server_at_boot", false);
|
||||||
|
}
|
||||||
|
|
||||||
return new Settings(
|
return new Settings(
|
||||||
data.get("hostname").getAsString(),
|
data.get("hostname").getAsString(),
|
||||||
data.get("port").getAsInt(),
|
data.get("port").getAsInt(),
|
||||||
data.get("config").getAsString()
|
data.get("config").getAsString(),
|
||||||
|
|
||||||
|
data.get("mobile_show_navigation_labels").getAsBoolean(),
|
||||||
|
data.get("mobile_disable_launcher_delay").getAsBoolean(),
|
||||||
|
data.get("mobile_start_server_at_boot").getAsBoolean()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ public class SettingsSerializer implements JsonSerializer<Settings> {
|
|||||||
result.add("port", new JsonPrimitive(settings.port));
|
result.add("port", new JsonPrimitive(settings.port));
|
||||||
result.add("config", new JsonPrimitive(settings.config));
|
result.add("config", new JsonPrimitive(settings.config));
|
||||||
|
|
||||||
|
result.add("mobile_show_navigation_labels", new JsonPrimitive(settings.mobileShowNavigationLabels));
|
||||||
|
result.add("mobile_disable_launcher_delay", new JsonPrimitive(settings.mobileDisableLauncherDelay));
|
||||||
|
result.add("mobile_start_server_at_boot", new JsonPrimitive(settings.mobileStartServerAtBoot));
|
||||||
|
|
||||||
container.add("data", result);
|
container.add("data", result);
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
|
|||||||
@@ -5,14 +5,17 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.Switch;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.lifecycle.Observer;
|
|
||||||
import androidx.lifecycle.ViewModelProviders;
|
|
||||||
import androidx.navigation.Navigation;
|
import androidx.navigation.Navigation;
|
||||||
|
|
||||||
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||||
|
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
|
||||||
|
|
||||||
import org.timecrafters.TimeCraftersConfigurationTool.R;
|
import org.timecrafters.TimeCraftersConfigurationTool.R;
|
||||||
|
import org.timecrafters.TimeCraftersConfigurationTool.backend.Backend;
|
||||||
import org.timecrafters.TimeCraftersConfigurationTool.library.TimeCraftersFragment;
|
import org.timecrafters.TimeCraftersConfigurationTool.library.TimeCraftersFragment;
|
||||||
|
|
||||||
public class SettingsFragment extends TimeCraftersFragment {
|
public class SettingsFragment extends TimeCraftersFragment {
|
||||||
@@ -22,6 +25,11 @@ public class SettingsFragment extends TimeCraftersFragment {
|
|||||||
final View root = inflater.inflate(R.layout.fragment_settings, container, false);
|
final View root = inflater.inflate(R.layout.fragment_settings, container, false);
|
||||||
final Button managePresets = root.findViewById(R.id.manage_presets);
|
final Button managePresets = root.findViewById(R.id.manage_presets);
|
||||||
final Button manageConfigurations = root.findViewById(R.id.manage_configurations);
|
final Button manageConfigurations = root.findViewById(R.id.manage_configurations);
|
||||||
|
final Switch showNavigationLabels = root.findViewById(R.id.show_navigation_labels);
|
||||||
|
final Switch disableLauncherDelay = root.findViewById(R.id.disable_launcher_delay);
|
||||||
|
final Switch startServerAtBoot = root.findViewById(R.id.start_server_at_boot);
|
||||||
|
|
||||||
|
final BottomNavigationView navView = getActivity().findViewById(R.id.nav_view);
|
||||||
|
|
||||||
managePresets.setOnClickListener(new View.OnClickListener() {
|
managePresets.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -37,6 +45,51 @@ public class SettingsFragment extends TimeCraftersFragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
showNavigationLabels.setChecked(Backend.instance().getSettings().mobileShowNavigationLabels);
|
||||||
|
styleSwitch(showNavigationLabels, Backend.instance().getSettings().mobileShowNavigationLabels);
|
||||||
|
|
||||||
|
disableLauncherDelay.setChecked(Backend.instance().getSettings().mobileDisableLauncherDelay);
|
||||||
|
styleSwitch(disableLauncherDelay, Backend.instance().getSettings().mobileDisableLauncherDelay);
|
||||||
|
|
||||||
|
startServerAtBoot.setChecked(Backend.instance().getSettings().mobileStartServerAtBoot);
|
||||||
|
styleSwitch(startServerAtBoot, Backend.instance().getSettings().mobileStartServerAtBoot);
|
||||||
|
|
||||||
|
showNavigationLabels.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
Backend.instance().getSettings().mobileShowNavigationLabels = isChecked;
|
||||||
|
Backend.instance().saveSettings();
|
||||||
|
|
||||||
|
if (isChecked) {
|
||||||
|
navView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
|
||||||
|
} else {
|
||||||
|
navView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED);
|
||||||
|
}
|
||||||
|
|
||||||
|
styleSwitch(buttonView, isChecked);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
disableLauncherDelay.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
Backend.instance().getSettings().mobileDisableLauncherDelay = isChecked;
|
||||||
|
Backend.instance().saveSettings();
|
||||||
|
|
||||||
|
styleSwitch(buttonView, isChecked);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
startServerAtBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
Backend.instance().getSettings().mobileStartServerAtBoot = isChecked;
|
||||||
|
Backend.instance().saveSettings();
|
||||||
|
|
||||||
|
styleSwitch(buttonView, isChecked);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<ScrollView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
@@ -38,4 +43,37 @@
|
|||||||
android:text="@string/settings_manage_configurations" />
|
android:text="@string/settings_manage_configurations" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="36dp"
|
||||||
|
android:background="@color/list_even"
|
||||||
|
android:orientation="vertical"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/show_navigation_labels"
|
||||||
|
style="@style/Button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/settings_show_navigation_labels" />
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/disable_launcher_delay"
|
||||||
|
style="@style/Button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/settings_disable_launcher_delay" />
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/start_server_at_boot"
|
||||||
|
style="@style/Button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/settings_start_server_at_boot" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
@@ -47,4 +47,7 @@
|
|||||||
<string name="add_from_preset">Add from preset</string>
|
<string name="add_from_preset">Add from preset</string>
|
||||||
<string name="add_variable">Add Variable</string>
|
<string name="add_variable">Add Variable</string>
|
||||||
<string name="variables">Variables</string>
|
<string name="variables">Variables</string>
|
||||||
|
<string name="settings_disable_launcher_delay">Disable Launcher Delay</string>
|
||||||
|
<string name="settings_start_server_at_boot">Start Server At Boot</string>
|
||||||
|
<string name="settings_show_navigation_labels">Show Navigation Labels</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user