Remove unnecessary getUser call

This commit is contained in:
Andrew Rabert 2020-05-22 17:49:43 -04:00
parent d1f1331f35
commit d10ea92edd
7 changed files with 0 additions and 100 deletions

View File

@ -835,7 +835,6 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
} }
Util.setActiveServer(this, instance); Util.setActiveServer(this, instance);
invalidate(); invalidate();
UserUtil.refreshCurrentUser(this);
updateDrawerHeader(); updateDrawerHeader();
} }
} }
@ -863,7 +862,6 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
service.setOnline(isOffline); service.setOnline(isOffline);
} }
UserUtil.seedCurrentUser(this);
this.updateDrawerHeader(); this.updateDrawerHeader();
drawer.closeDrawers(); drawer.closeDrawers();
} }

View File

@ -367,7 +367,6 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
getIntent().removeExtra(Constants.INTENT_EXTRA_VIEW_ALBUM); getIntent().removeExtra(Constants.INTENT_EXTRA_VIEW_ALBUM);
} }
UserUtil.seedCurrentUser(this);
createAccount(); createAccount();
runWhenServiceAvailable(() -> getDownloadService().addOnSongChangedListener(SubsonicFragmentActivity.this)); runWhenServiceAvailable(() -> getDownloadService().addOnSongChangedListener(SubsonicFragmentActivity.this));
resuming = false; resuming = false;

View File

@ -616,24 +616,6 @@ public class CachedMusicService implements MusicService {
} }
} }
@Override
public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) {
User result = null;
try {
result = musicService.getUser(refresh, username, context, progressListener);
FileUtil.serialize(context, result, getCacheName(context, "user-" + username));
} catch (Exception e) {
// Don't care
}
if (result == null && !refresh) {
result = FileUtil.deserialize(context, getCacheName(context, "user-" + username), User.class);
}
return result;
}
@Override @Override
public void startScan(Context c) throws Exception { public void startScan(Context c) throws Exception {
musicService.startScan(c); musicService.startScan(c);

View File

@ -87,8 +87,6 @@ public interface MusicService {
MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception; MusicDirectory getSongsByGenre(String genre, int count, int offset, 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 startScan(Context c) throws Exception;
void setInstance(Integer instance) throws Exception; void setInstance(Integer instance) throws Exception;

View File

@ -500,11 +500,6 @@ public class OfflineMusicService implements MusicService {
return result; return result;
} }
@Override
public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception {
throw new OfflineException();
}
@Override @Override
public void startScan(Context c) throws Exception { public void startScan(Context c) throws Exception {
throw new OfflineException(); throw new OfflineException();

View File

@ -656,29 +656,6 @@ public class RESTMusicService implements MusicService {
} }
} }
@Override
public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception {
Map<String, String> parameters = new HashMap<>();
parameters.put("username", username);
String url = getRestUrl(context, "getUser", parameters);
Request request = new Request.Builder()
.url(url)
.build();
try (Response response = client.newCall(request).execute()) {
List<User> users = new UserParser(context, getInstance(context)).parse(response.body().byteStream());
if (users.size() > 0) {
// Should only have returned one anyways
return users.get(0);
} else {
return null;
}
}
}
@Override @Override
public void startScan(Context context) throws Exception { public void startScan(Context context) throws Exception {
String url = getRestUrl(context, "startScan", null); String url = getRestUrl(context, "startScan", null);

View File

@ -25,55 +25,6 @@ import net.nullsum.audinaut.domain.User;
import net.nullsum.audinaut.service.MusicServiceFactory; import net.nullsum.audinaut.service.MusicServiceFactory;
public final class UserUtil { public final class UserUtil {
private static final String TAG = UserUtil.class.getSimpleName();
private static int instance = -1;
private static int instanceHash = -1;
private static User currentUser;
public static void refreshCurrentUser(Context context) {
currentUser = null;
seedCurrentUser(context);
}
public static void seedCurrentUser(Context context) {
// Only try to seed if online
if (Util.isOffline(context)) {
currentUser = null;
return;
}
final int instance = Util.getActiveServer(context);
final int instanceHash = (instance == 0) ? 0 : Util.getRestUrl(context).hashCode();
if (UserUtil.instance == instance && UserUtil.instanceHash == instanceHash && currentUser != null) {
return;
} else {
UserUtil.instance = instance;
UserUtil.instanceHash = instanceHash;
}
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
currentUser = MusicServiceFactory.getMusicService(context).getUser(false, getCurrentUsername(context, instance), context, null);
return null;
}
@Override
protected void done(Void result) {
if (context instanceof AppCompatActivity) {
((AppCompatActivity) context).supportInvalidateOptionsMenu();
}
}
@Override
protected void error(Throwable error) {
// Don't do anything, supposed to be background pull
Log.e(TAG, "Failed to seed user information");
}
}.execute();
}
private static String getCurrentUsername(Context context, int instance) { private static String getCurrentUsername(Context context, int instance) {
SharedPreferences prefs = Util.getPreferences(context); SharedPreferences prefs = Util.getPreferences(context);
return prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null); return prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null);