Remove unnecessary getUser call
This commit is contained in:
parent
d1f1331f35
commit
d10ea92edd
|
@ -835,7 +835,6 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
|
|||
}
|
||||
Util.setActiveServer(this, instance);
|
||||
invalidate();
|
||||
UserUtil.refreshCurrentUser(this);
|
||||
updateDrawerHeader();
|
||||
}
|
||||
}
|
||||
|
@ -863,7 +862,6 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
|
|||
service.setOnline(isOffline);
|
||||
}
|
||||
|
||||
UserUtil.seedCurrentUser(this);
|
||||
this.updateDrawerHeader();
|
||||
drawer.closeDrawers();
|
||||
}
|
||||
|
|
|
@ -367,7 +367,6 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
|
|||
getIntent().removeExtra(Constants.INTENT_EXTRA_VIEW_ALBUM);
|
||||
}
|
||||
|
||||
UserUtil.seedCurrentUser(this);
|
||||
createAccount();
|
||||
runWhenServiceAvailable(() -> getDownloadService().addOnSongChangedListener(SubsonicFragmentActivity.this));
|
||||
resuming = false;
|
||||
|
|
|
@ -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
|
||||
public void startScan(Context c) throws Exception {
|
||||
musicService.startScan(c);
|
||||
|
|
|
@ -87,8 +87,6 @@ public interface MusicService {
|
|||
|
||||
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 setInstance(Integer instance) throws Exception;
|
||||
|
|
|
@ -500,11 +500,6 @@ public class OfflineMusicService implements MusicService {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception {
|
||||
throw new OfflineException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startScan(Context c) throws Exception {
|
||||
throw new OfflineException();
|
||||
|
|
|
@ -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
|
||||
public void startScan(Context context) throws Exception {
|
||||
String url = getRestUrl(context, "startScan", null);
|
||||
|
|
|
@ -25,55 +25,6 @@ import net.nullsum.audinaut.domain.User;
|
|||
import net.nullsum.audinaut.service.MusicServiceFactory;
|
||||
|
||||
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) {
|
||||
SharedPreferences prefs = Util.getPreferences(context);
|
||||
return prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null);
|
||||
|
|
Loading…
Reference in New Issue