android: allow opening project detail activity even when project already attached.

This commit is contained in:
Joachim Fritzsch 2013-07-13 14:40:31 +02:00
parent bcaf537228
commit cd804778ff
3 changed files with 54 additions and 39 deletions

View File

@ -349,13 +349,11 @@
</LinearLayout>
<ProgressBar
android:id="@+id/login_pending"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
<!-- attached -->
<include
android:id="@+id/attached_wrapper"
layout="@layout/attach_project_success_layout"
android:layout_marginTop="20dp"
android:visibility="gone" />
</LinearLayout>

View File

@ -66,6 +66,7 @@
<string name="attachproject_login_button_registration">Register</string>
<string name="attachproject_login_button_login">Sign in</string>
<string name="attachproject_login_error_toast">Contacting project failed!</string>
<string name="attachproject_login_attached">Attached</string>
<!-- project registration -->
<string name="attachproject_registration_header">Account registration for </string>
<string name="attachproject_registration_header_url">Project:</string>
@ -76,7 +77,6 @@
<string name="attachproject_registration_header_pwd_confirm">&#8230; Retype:</string>
<string name="attachproject_registration_button">Create</string>
<!-- error strings -->
<string name="attachproject_error_project_exists">Project is already attached</string>
<string name="attachproject_error_wrong_name">User not found</string>
<string name="attachproject_error_short_pwd">Password too short</string>
<string name="attachproject_error_no_internet">Connection failure</string>

View File

@ -165,8 +165,8 @@ public class AttachProjectLoginActivity extends Activity{
}
// gets called by GetProjectConfig when ProjectConfig is available
private void populateLayout() {
if(Logging.DEBUG) Log.d(Logging.TAG, "populateLayout");
private void populateLayout(Boolean projectAlreadyAttached) {
if(Logging.DEBUG) Log.d(Logging.TAG, "AttachProjectLoginActivity.populateLayout: projectAlreadyAttached: " + projectAlreadyAttached);
setContentView(R.layout.attach_project_login_layout);
@ -253,6 +253,10 @@ public class AttachProjectLoginActivity extends Activity{
}
// set account creation
if(projectAlreadyAttached) {
LinearLayout creationWrapper = (LinearLayout) findViewById(R.id.creation_wrapper);
creationWrapper.setVisibility(View.GONE);
} else{
TextView creationCategory = (TextView) findViewById(R.id.category_creation);
creationCategory.setText(getString(R.string.attachproject_login_category_creation) + " " + projectConfig.name + "?");
TextView creationText = (TextView) findViewById(R.id.creation_action);
@ -268,8 +272,13 @@ public class AttachProjectLoginActivity extends Activity{
creationText.setText(R.string.attachproject_login_header_creation_enabled);
creationSubmit.setTag(true);
}
}
// set account login
if(projectAlreadyAttached) {
LinearLayout loginWrapper = (LinearLayout) findViewById(R.id.login_wrapper);
loginWrapper.setVisibility(View.GONE);
} else {
TextView loginCategory = (TextView) findViewById(R.id.category_login);
loginCategory.setText(R.string.attachproject_login_category_login);
if(projectConfig.userName) { // user vs. email?
@ -281,6 +290,15 @@ public class AttachProjectLoginActivity extends Activity{
}
}
// set project attached
if(projectAlreadyAttached) {
LinearLayout attachedWrapper = (LinearLayout) findViewById(R.id.attached_wrapper);
attachedWrapper.setVisibility(View.VISIBLE);
TextView header = (TextView) attachedWrapper.findViewById(R.id.header);
header.setText(R.string.attachproject_login_attached);
}
}
public void login (View view) {
// parse user input
EditText idInput = (EditText) findViewById(R.id.id_input);
@ -358,6 +376,8 @@ public class AttachProjectLoginActivity extends Activity{
private final class GetProjectConfig extends AsyncTask<String, Void, Integer> {
private boolean projectAlreadyAttached = false;
@Override
protected Integer doInBackground(String... params) {
String url = params[0];
@ -368,15 +388,11 @@ public class AttachProjectLoginActivity extends Activity{
if(!projectInfoPresent) { // only url string is available
if(Logging.DEBUG) Log.d(Logging.TAG, "doInBackground() - GetProjectConfig for manual input url: " + url);
if(checkProjectAlreadyAttached(url)) return R.string.attachproject_error_project_exists;
//fetch ProjectConfig
projectConfig = monitor.getProjectConfig(url);
} else {
if(Logging.DEBUG) Log.d(Logging.TAG, "doInBackground() - GetProjectConfig for list selection url: " + projectInfo.url);
if(checkProjectAlreadyAttached(projectInfo.url)) return R.string.attachproject_error_project_exists;
//fetch ProjectConfig
projectConfig = monitor.getProjectConfig(projectInfo.url);
@ -386,6 +402,7 @@ public class AttachProjectLoginActivity extends Activity{
if (projectConfig != null && projectConfig.error_num != null && projectConfig.error_num == 0) {
// success
projectAlreadyAttached = checkProjectAlreadyAttached(projectInfo.url);
return 0;
} else {
if(Logging.DEBUG) if(projectConfig != null) Log.d(Logging.TAG,"getProjectConfig returned error num:" + projectConfig.error_num);
@ -404,7 +421,7 @@ public class AttachProjectLoginActivity extends Activity{
protected void onPostExecute(Integer toastStringId) {
if(toastStringId == 0) { // no error, no toast...
if(Logging.DEBUG) Log.d(Logging.TAG, "onPostExecute() - GetProjectConfig successful.");
populateLayout();
populateLayout(projectAlreadyAttached);
} else {
finish(toastStringId);
}