Merge pull request #72 from simao/start-scan-option

Start scan option
This commit is contained in:
Andrew Rabert 2020-03-14 11:36:40 -04:00 committed by GitHub
commit 26848852ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 84 additions and 0 deletions

View File

@ -530,6 +530,15 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared
return false; return false;
}); });
Preference serverStartScanPreference = new Preference(context);
serverStartScanPreference.setKey(Constants.PREFERENCES_KEY_START_SCAN + instance);
serverStartScanPreference.setPersistent(false);
serverStartScanPreference.setTitle(R.string.settings_start_scan_title);
serverStartScanPreference.setOnPreferenceClickListener(preference -> {
startScan(instance);
return false;
});
screen.addPreference(serverNamePreference); screen.addPreference(serverNamePreference);
screen.addPreference(serverUrlPreference); screen.addPreference(serverUrlPreference);
screen.addPreference(serverInternalUrlPreference); screen.addPreference(serverInternalUrlPreference);
@ -538,6 +547,7 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared
screen.addPreference(serverPasswordPreference); screen.addPreference(serverPasswordPreference);
screen.addPreference(authMethodPreference); screen.addPreference(authMethodPreference);
screen.addPreference(serverTestConnectionPreference); screen.addPreference(serverTestConnectionPreference);
screen.addPreference(serverStartScanPreference);
screen.addPreference(serverOpenBrowser); screen.addPreference(serverOpenBrowser);
screen.addPreference(serverRemoveServerPreference); screen.addPreference(serverRemoveServerPreference);
@ -607,6 +617,42 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared
} }
} }
private void startScan(final int instance) {
LoadingTask<Boolean> task = new LoadingTask<Boolean>(context) {
@Override
protected Boolean doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getOnlineService();
try {
musicService.setInstance(instance);
musicService.startScan(context);
return true;
} finally {
musicService.setInstance(null);
}
}
@Override
protected void done(Boolean licenseValid) {
Log.d(TAG, "Finished media scan start");
Util.toast(context, R.string.settings_media_scan_started);
}
@Override
public void cancel() {
super.cancel();
}
@Override
protected void error(Throwable error) {
Log.w(TAG, error.toString(), error);
new ErrorDialog(context, getResources().getString(R.string.settings_media_scan_start_failed) +
" " + getErrorMessage(error), false);
}
};
task.execute();
}
private void testConnection(final int instance) { private void testConnection(final int instance) {
LoadingTask<Boolean> task = new LoadingTask<Boolean>(context) { LoadingTask<Boolean> task = new LoadingTask<Boolean>(context) {
private int previousInstance; private int previousInstance;

View File

@ -634,6 +634,11 @@ public class CachedMusicService implements MusicService {
return result; return result;
} }
@Override
public void startScan(Context c) throws Exception {
musicService.startScan(c);
}
@Override @Override
public void setInstance(Integer instance) { public void setInstance(Integer instance) {
musicService.setInstance(instance); musicService.setInstance(instance);

View File

@ -89,5 +89,7 @@ public interface MusicService {
User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception; User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception;
void startScan(Context c) throws Exception;
void setInstance(Integer instance) throws Exception; void setInstance(Integer instance) throws Exception;
} }

View File

@ -44,6 +44,7 @@ import java.io.FileReader;
import java.io.Reader; import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -503,6 +504,11 @@ public class OfflineMusicService implements MusicService {
throw new OfflineException(); throw new OfflineException();
} }
@Override
public void startScan(Context c) throws Exception {
throw new OfflineException();
}
@Override @Override
public void setInstance(Integer instance) throws Exception { public void setInstance(Integer instance) throws Exception {
throw new OfflineException(); throw new OfflineException();

View File

@ -25,6 +25,7 @@ import android.util.Log;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import net.nullsum.audinaut.R;
import net.nullsum.audinaut.domain.Genre; import net.nullsum.audinaut.domain.Genre;
import net.nullsum.audinaut.domain.Indexes; import net.nullsum.audinaut.domain.Indexes;
import net.nullsum.audinaut.domain.MusicDirectory; import net.nullsum.audinaut.domain.MusicDirectory;
@ -678,6 +679,22 @@ public class RESTMusicService implements MusicService {
} }
} }
@Override
public void startScan(Context context) throws Exception {
String url = getRestUrl(context, "startScan", null);
Request request = new Request.Builder().url(url).build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
Log.d(TAG, "Media scan started" + response.toString());
} else {
Log.w(TAG, "media scan start failed" + response.toString());
Util.toast(context, R.string.settings_media_scan_start_failed);
}
}
}
private String getOfflineSongId(String id, Context context, ProgressListener progressListener) throws Exception { private String getOfflineSongId(String id, Context context, ProgressListener progressListener) throws Exception {
SharedPreferences prefs = Util.getPreferences(context); SharedPreferences prefs = Util.getPreferences(context);
String cacheLocn = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null); String cacheLocn = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null);

View File

@ -67,6 +67,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_SERVER_INTERNAL_URL = "serverInternalUrl"; public static final String PREFERENCES_KEY_SERVER_INTERNAL_URL = "serverInternalUrl";
public static final String PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID = "serverLocalNetworkSSID"; public static final String PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID = "serverLocalNetworkSSID";
public static final String PREFERENCES_KEY_TEST_CONNECTION = "serverTestConnection"; public static final String PREFERENCES_KEY_TEST_CONNECTION = "serverTestConnection";
public static final String PREFERENCES_KEY_START_SCAN = "serverStartScan";
public static final String PREFERENCES_KEY_OPEN_BROWSER = "openBrowser"; public static final String PREFERENCES_KEY_OPEN_BROWSER = "openBrowser";
public static final String PREFERENCES_KEY_MUSIC_FOLDER_ID = "musicFolderId"; public static final String PREFERENCES_KEY_MUSIC_FOLDER_ID = "musicFolderId";
public static final String PREFERENCES_KEY_USERNAME = "username"; public static final String PREFERENCES_KEY_USERNAME = "username";

View File

@ -18,6 +18,7 @@ package net.nullsum.audinaut.util;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.util.Log;
import net.nullsum.audinaut.R; import net.nullsum.audinaut.R;
import net.nullsum.audinaut.activity.SettingsActivity; import net.nullsum.audinaut.activity.SettingsActivity;
@ -58,6 +59,9 @@ public final class ThemeUtil {
} }
private static int getThemeRes(Context context, String theme) { private static int getThemeRes(Context context, String theme) {
if(theme == null)
return R.style.Theme_Audinaut_Light;
switch (theme) { switch (theme) {
case THEME_DARK: case THEME_DARK:
return R.style.Theme_Audinaut_Dark; return R.style.Theme_Audinaut_Dark;

View File

@ -124,6 +124,7 @@
<string name="settings.title">Settings</string> <string name="settings.title">Settings</string>
<string name="settings.test_connection_title">Test connection</string> <string name="settings.test_connection_title">Test connection</string>
<string name="settings.start_scan_title">Start Media Scan Now</string>
<string name="settings.servers_add">Add Server</string> <string name="settings.servers_add">Add Server</string>
<string name="settings.servers_remove">Remove Server</string> <string name="settings.servers_remove">Remove Server</string>
<string name="settings.servers_title">Servers</string> <string name="settings.servers_title">Servers</string>
@ -152,6 +153,8 @@
<string name="settings.testing_connection">Testing connection…</string> <string name="settings.testing_connection">Testing connection…</string>
<string name="settings.testing_ok">Connection is OK</string> <string name="settings.testing_ok">Connection is OK</string>
<string name="settings.connection_failure">Connection failure.</string> <string name="settings.connection_failure">Connection failure.</string>
<string name="settings.media_scan_started">Media scan started</string>
<string name="settings.media_scan_start_failed">Could not start media scan</string>
<string name="settings.invalid_url">Please specify a valid URL.</string> <string name="settings.invalid_url">Please specify a valid URL.</string>
<string name="settings.invalid_username">Please specify a valid username (no trailing spaces).</string> <string name="settings.invalid_username">Please specify a valid username (no trailing spaces).</string>
<string name="settings.appearance_title">Appearance</string> <string name="settings.appearance_title">Appearance</string>