Improved Settings Activity UX

This commit is contained in:
Stefan Niedermann 2015-10-22 22:01:58 +02:00
parent b92810a1f3
commit 896121bb62
3 changed files with 38 additions and 144 deletions

View file

@ -50,9 +50,7 @@ public class NotesListViewActivity extends AppCompatActivity implements
// First Run Wizard
SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
Log.v("Note", "First Run: " + preferences.getBoolean(SettingsActivity.SETTINGS_FIRST_RUN, true));
if(preferences.getBoolean(SettingsActivity.SETTINGS_FIRST_RUN, true)) {
Log.v("Note", "Seems to be the First Run...");
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivityForResult(settingsIntent, server_settings);
}
@ -198,77 +196,21 @@ public class NotesListViewActivity extends AppCompatActivity implements
}
} else if (requestCode == NoteActivity.EDIT_NOTE_CMD) {
if (resultCode == RESULT_OK) {
Log.v("Note", "Note was edited from single view");
Note editedNote = (Note) data.getExtras().getSerializable(
NoteActivity.EDIT_NOTE);
Log.v("Note", "Neuer Titel: " + editedNote);
int notePosition = data.getExtras().getInt(
SELECTED_NOTE_POSITION);
Log.v("Note", "notePosition | NotesListViewActivity kam an "
+ notePosition);
adapter.remove(adapter.getItem(notePosition));
adapter.add(editedNote);
}
} else if (requestCode == SettingsActivity.CREDENTIALS_CHANGED) {
Log.v("Note", "Credentials Changed!");
db = new NoteSQLiteOpenHelper(this);
db.synchronizeWithServer(); // Needed to instanciate new NotesClient with new URL
}
Log.v("Note", "New NoteSQLteOpenHelper instanciated");
//TODO Maybe only if previous activity == settings activity?
setListView(db.getNotes());
}
// private class SingleSelectedActionModeCallback implements
// ActionMode.Callback {
//
// @Override
// public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// // inflate contextual menu
// mode.getMenuInflater().inflate(R.menu.menu_list_context_single,
// menu);
// return true;
// }
//
// @Override
// public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// return false;
// }
//
// @Override
// public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// switch (item.getItemId()) {
// case R.id.menu_delete:
// SparseBooleanArray checkedItemPositions = listView
// .getCheckedItemPositions();
// for (int i = (checkedItemPositions.size() - 1); i >= 0; i--) {
// if (checkedItemPositions.valueAt(i)) {
//
// Note checkedItem = adapter.getItem(checkedItemPositions
// .keyAt(i));
//
// NoteDeleterAsyncTask deleter = new NoteDeleterAsyncTask();
// deleter.execute(checkedItem);
// }
// }
// mode.finish(); // Action picked, so close the CAB
// return true;
// default:
// return false;
// }
// }
//
// @Override
// public void onDestroyActionMode(ActionMode mode) {
// removeSelection();
// mActionMode = null;
// adapter.notifyDataSetChanged();
// }
// }
/**
* Long click on one item in the list view. It starts the Action Mode and allows selecting more
* items and execute bulk functions (e. g. delete)

View file

@ -2,12 +2,15 @@ package it.niedermann.owncloud.notes.android.activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@ -20,7 +23,7 @@ import it.niedermann.owncloud.notes.util.NotesClientUtil;
* Allows to set Settings like URL, Username and Password for Server-Synchronization
* Created by stefan on 22.09.15.
*/
public class SettingsActivity extends AppCompatActivity implements View.OnClickListener {
public class SettingsActivity extends AppCompatActivity {
public static final String SETTINGS_FIRST_RUN = "firstRun";
public static final String SETTINGS_URL = "settingsUrl";
@ -75,34 +78,22 @@ public class SettingsActivity extends AppCompatActivity implements View.OnClickL
field_username.setText(preferences.getString(SETTINGS_USERNAME, DEFAULT_SETTINGS));
field_password.setText(preferences.getString(SETTINGS_PASSWORD, DEFAULT_SETTINGS));
btn_submit.setOnClickListener(this);
findViewById(R.id.settings_submit).setOnClickListener(new View.OnClickListener() {
btn_submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(SettingsActivity.this, NotesListViewActivity.class));
String url = field_url.getText().toString();
String username = field_username.getText().toString();
String password = field_password.getText().toString();
if (!url.endsWith("/")) {
url += "/";
}
new LoginValidatorAsyncTask().execute(url, username, password);
}
});
}
/**
* Handle Submit Button Click
* Checks and Writes the new Preferences into the SharedPreferences Object.
*
* @param v View
*/
@Override
public void onClick(View v) {
String url = field_url.getText().toString();
String username = field_username.getText().toString();
String password = field_password.getText().toString();
if (!url.endsWith("/")) {
url += "/";
}
new LoginValidatorAsyncTask().execute(url, username, password);
}
/************************************ Async Tasks ************************************/
/**
@ -113,7 +104,7 @@ public class SettingsActivity extends AppCompatActivity implements View.OnClickL
@Override
protected void onPreExecute() {
findViewById(R.id.settings_url_check).setVisibility(View.INVISIBLE);
((EditText) findViewById(R.id.settings_url)).setCompoundDrawables(null, null, null, null);
}
@Override
@ -124,9 +115,11 @@ public class SettingsActivity extends AppCompatActivity implements View.OnClickL
@Override
protected void onPostExecute(Boolean o) {
if (o) {
findViewById(R.id.settings_url_check).setVisibility(View.VISIBLE);
Drawable actionDoneDark = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_action_done_dark);
actionDoneDark.setBounds(0, 0, 50, 50);
((EditText) findViewById(R.id.settings_url)).setCompoundDrawables(null, null, actionDoneDark, null);
} else {
findViewById(R.id.settings_url_check).setVisibility(View.INVISIBLE);
((EditText) findViewById(R.id.settings_url)).setCompoundDrawables(null, null, null, null);
}
}
}
@ -176,6 +169,7 @@ public class SettingsActivity extends AppCompatActivity implements View.OnClickL
setResult(RESULT_OK, data);
finish();
} else {
Log.e("Note", "invalid login");
btn_submit.setEnabled(true);
//TODO Show Error Message
}

View file

@ -1,103 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.GridLayout
android:id="@+id/settings_grid_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_horizontal_margin"
app:columnCount="2"
app:orientation="horizontal"
>
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<android.support.design.widget.TextInputLayout
android:id="@+id/settings_url_wrapper"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_column="0"
app:layout_row="0"
app:layout_gravity="fill"
>
android:layout_marginTop="@dimen/default_gap">
<EditText
android:id="@+id/settings_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/settings_url"
android:inputType="textUri"/>
android:inputType="textUri" />
</android.support.design.widget.TextInputLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/settings_url_check"
android:src="@drawable/ic_action_done_dark"
android:contentDescription="@string/settings_url_check_description"
android:visibility="invisible"
app:layout_column="1"
app:layout_row="0"
/>
<TextView
android:id="@+id/settings_url_warn_http"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/settings_url_warn_http"
android:visibility="gone"
android:text="@string/settings_url_warn_http"
app:layout_columnSpan="2"/>
android:visibility="gone" />
<android.support.design.widget.TextInputLayout
android:id="@+id/settings_username_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_column="0"
app:layout_row="2"
app:layout_gravity="fill">
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/settings_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/settings_username"/>
android:hint="@string/settings_username" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/settings_password_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_column="0"
app:layout_row="3"
app:layout_gravity="fill">
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/settings_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/settings_password"
android:inputType="textPassword"/>
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/settings_password_check"
android:src="@drawable/ic_action_done_dark"
android:contentDescription="@string/settings_password_check_description"
android:visibility="invisible"
app:layout_column="1"
app:layout_row="3"
/>
<Button
android:id="@+id/settings_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shadowColor="@color/fg_default_low"
android:text="@string/settings_submit"
app:layout_gravity="end"
app:layout_row="4"
app:layout_column="0"
app:layout_columnSpan="2"
/>
</android.support.v7.widget.GridLayout>
android:text="@string/settings_submit" />
</LinearLayout>