#1500 Makes Channel Auto-Start timeout a user-preference item to select in range 0-30 seconds. (#1501)

Co-authored-by: Dennis Sheirer <dsheirer@github.com>
This commit is contained in:
Denny Sheirer
2023-03-21 04:32:28 -04:00
committed by GitHub
parent 366055145e
commit 2782953518
9 changed files with 228 additions and 27 deletions

View File

@@ -0,0 +1,80 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/
package io.github.dsheirer.preference.application;
import io.github.dsheirer.preference.Preference;
import io.github.dsheirer.preference.PreferenceType;
import io.github.dsheirer.sample.Listener;
import java.util.prefs.Preferences;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* General/Miscellaneous preferences
*/
public class ApplicationPreference extends Preference
{
private static final String PREFERENCE_KEY_CHANNEL_AUTO_START_TIMEOUT = "channel.auto.start.timeout";
private final static Logger mLog = LoggerFactory.getLogger(ApplicationPreference.class);
private Preferences mPreferences = Preferences.userNodeForPackage(ApplicationPreference.class);
private Integer mChannelAutoStartTimeout;
/**
* Constructs an instance
* @param updateListener to receive notifications that a preference has been updated
*/
public ApplicationPreference(Listener<PreferenceType> updateListener)
{
super(updateListener);
}
@Override
public PreferenceType getPreferenceType()
{
return PreferenceType.APPLICATION;
}
/**
* Channel auto-start timeout. This is the countdown in seconds to allow the user to cancel the channel auto-start.
* @return timeout in seconds.
*/
public int getChannelAutoStartTimeout()
{
if(mChannelAutoStartTimeout == null)
{
mChannelAutoStartTimeout = mPreferences.getInt(PREFERENCE_KEY_CHANNEL_AUTO_START_TIMEOUT, 10);
}
return mChannelAutoStartTimeout;
}
/**
* Sets the channel auto-start timeout seconds value.
* @param timeout in seconds.
*/
public void setChannelAutoStartTimeout(int timeout)
{
mChannelAutoStartTimeout = timeout;
mPreferences.putInt(PREFERENCE_KEY_CHANNEL_AUTO_START_TIMEOUT, timeout);
notifyPreferenceUpdated();
}
}