Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Startup activity mess #324

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/src/main/java/org/jellyfin/androidtv/TvApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public void setConnectionManager(IConnectionManager connectionManager) {
}

public UserDto getCurrentUser() {
if (currentUser == null)
logger.Error("Called getCurrentUser() but value was null.");

return currentUser;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import androidx.fragment.app.FragmentActivity;

public class StartupActivity extends FragmentActivity {

private static final int NETWORK_PERMISSION = 1;
private TvApp application;
private ILogger logger;
Expand All @@ -53,7 +52,6 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_startup);


application = (TvApp) getApplicationContext();
logger = application.getLogger();

Expand Down Expand Up @@ -96,41 +94,33 @@ private void start() {
// go straight into last connection
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
} else {
//clear audio queue in case left over from last run
MediaManager.clearAudioQueue();
MediaManager.clearVideoQueue();
establishConnection(this);
establishConnection();
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case NETWORK_PERMISSION: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {

// permission was granted, yay!
start();
} else {

// permission denied, boo! Disable the
// functionality that depends on this permission.
Utils.showToast(this, "Application cannot continue without network");
finish();
}
return;
if (requestCode == NETWORK_PERMISSION) {// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted
start();
} else {
// permission denied! Disable the app.
Utils.showToast(this, "Application cannot continue without network");
finish();
}

// other 'case' lines to check for other
// permissions this app might request
}

}

private void establishConnection(final Activity activity){
private void establishConnection() {
// workaround...
Activity self = this;

// The underlying http stack. Developers can inject their own if desired
VolleyHttpClient volleyHttpClient = new VolleyHttpClient(logger, application);
TvApp.getApplication().setHttpClient(volleyHttpClient);
Expand Down Expand Up @@ -179,16 +169,16 @@ private void establishConnection(final Activity activity){
public void onResponse(ConnectionResult response) {
// Saved server login is unavailable
if (response.getState() == ConnectionState.Unavailable) {
Utils.showToast(activity, R.string.msg_error_server_unavailable + ": " + application.getConfiguredAutoCredentials().getServerInfo().getName());
AuthenticationHelper.automaticSignIn(connectionManager, activity);
Utils.showToast(self, R.string.msg_error_server_unavailable + ": " + application.getConfiguredAutoCredentials().getServerInfo().getName());
AuthenticationHelper.automaticSignIn(connectionManager, self);
return;
}

// Check the server version
if (!response.getServers().isEmpty() &&
!AuthenticationHelper.isSupportedServerVersion(response.getServers().get(0))) {
Utils.showToast(activity, activity.getString(R.string.msg_error_server_version, TvApp.MINIMUM_SERVER_VERSION));
AuthenticationHelper.automaticSignIn(connectionManager, activity);
Utils.showToast(self, getString(R.string.msg_error_server_version, TvApp.MINIMUM_SERVER_VERSION));
AuthenticationHelper.automaticSignIn(connectionManager, self);
return;
}

Expand All @@ -204,31 +194,33 @@ public void onResponse(final UserDto response) {
&& (!application.getIsAutoLoginConfigured()
|| (application.getPrefs().getBoolean("pref_auto_pw_prompt", false)))) {
//Need to prompt for pw
Utils.processPasswordEntry(activity, response, application.getDirectItemId());
Utils.processPasswordEntry(self, response, application.getDirectItemId());
} else {
//Can just go right into details
Intent detailsIntent = new Intent(activity, FullDetailsActivity.class);
Intent detailsIntent = new Intent(self, FullDetailsActivity.class);
detailsIntent.putExtra("ItemId", application.getDirectItemId());
startActivity(detailsIntent);
finish();
}
} else {
if (response.getHasPassword() && application.getPrefs().getBoolean("pref_auto_pw_prompt", false)) {
Utils.processPasswordEntry(activity, response);
Utils.processPasswordEntry(self, response);
} else {
Intent intent = new Intent(activity, MainActivity.class);
activity.startActivity(intent);
Intent intent = new Intent(self, MainActivity.class);
startActivity(intent);
finish();
}
}
}

@Override
public void onError(Exception exception) {
application.getLogger().ErrorException("Error Signing in", exception);
Utils.showToast(activity, R.string.msg_error_signin);
Utils.showToast(self, R.string.msg_error_signin);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
AuthenticationHelper.automaticSignIn(connectionManager, activity);
AuthenticationHelper.automaticSignIn(connectionManager, self);
}
}, 5000);
}
Expand All @@ -237,12 +229,12 @@ public void run() {

@Override
public void onError(Exception exception) {
Utils.showToast( activity, R.string.msg_error_connecting_server + ": " + application.getConfiguredAutoCredentials().getServerInfo().getName());
AuthenticationHelper.automaticSignIn(connectionManager, activity);
Utils.showToast(self, R.string.msg_error_connecting_server + ": " + application.getConfiguredAutoCredentials().getServerInfo().getName());
AuthenticationHelper.automaticSignIn(connectionManager, self);
}
});
} else {
AuthenticationHelper.automaticSignIn(connectionManager, activity);
AuthenticationHelper.automaticSignIn(connectionManager, self);
}
}
}