@Override public void onRequestStart(MegaApiJava api, MegaRequest request) { log("onRequestStart: " + request.getRequestString()); if (request.getType() == MegaRequest.TYPE_LOGIN) { title.setText(getResources().getString(R.string.logging_in)); } else if (request.getType() == MegaRequest.TYPE_FETCH_NODES) { title.setText(getResources().getString(R.string.fetching_nodes)); fetchingNodesBar.setVisibility(View.VISIBLE); fetchingNodesBar.getLayoutParams().width = 350; fetchingNodesBar.setProgress(0); } }
@Override public void onRequestUpdate(MegaApiJava api, MegaRequest request) { log("onRequestUpdate: " + request.getRequestString()); if (request.getType() == MegaRequest.TYPE_FETCH_NODES) { fetchingNodesBar.setVisibility(View.VISIBLE); fetchingNodesBar.getLayoutParams().width = 350; if (request.getTotalBytes() > 0) { double progressValue = 100.0 * request.getTransferredBytes() / request.getTotalBytes(); if ((progressValue > 99) || (progressValue < 0)) { progressValue = 100; title.setText(getResources().getString(R.string.preparing_nodes)); } log("progressValue = " + (int) progressValue); fetchingNodesBar.setProgress((int) progressValue); } } }
@Override public void onRequestFinish(MegaApiJava api, MegaRequest request, MegaError e) { log("onRequestFinish: " + request.getRequestString()); if (request.getType() == MegaRequest.TYPE_LOGIN) { if (e.getErrorCode() == MegaError.API_OK) { megaApi.fetchNodes(this); } else { String errorMessage = e.getErrorString(); if (e.getErrorCode() == MegaError.API_ENOENT) { errorMessage = getString(R.string.error_incorrect_email_or_password); } Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show(); title.setText(getResources().getString(R.string.login_text)); loginText.setVisibility(View.VISIBLE); passwordText.setVisibility(View.VISIBLE); loginButton.setVisibility(View.VISIBLE); } } else if (request.getType() == MegaRequest.TYPE_FETCH_NODES) { if (e.getErrorCode() != MegaError.API_OK) { Toast.makeText(this, e.getErrorString(), Toast.LENGTH_LONG).show(); title.setText(getResources().getString(R.string.login_text)); loginText.setVisibility(View.VISIBLE); passwordText.setVisibility(View.VISIBLE); loginButton.setVisibility(View.VISIBLE); fetchingNodesBar.setProgress(0); fetchingNodesBar.setVisibility(View.GONE); } else { Intent intent = new Intent(this, NavigationActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); } } }
@Override public void onRequestTemporaryError(MegaApiJava api, MegaRequest request, MegaError e) { log("onRequestTemporaryError: " + request.getRequestString()); }