Commit e9bb1b55 authored by Ricki Hirner's avatar Ricki Hirner

Add account details activity (AccountActivity)

parent dbbc0386
......@@ -14,6 +14,7 @@
<!-- normal permissions -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
......@@ -112,24 +113,27 @@
</intent-filter>
</activity>
<activity
android:name=".ui.setup.LoginActivity"
android:label="@string/login_title"
android:name=".ui.AccountActivity"
android:parentActivityName=".ui.AccountsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
<activity
android:name=".ui.DebugInfoActivity"
android:exported="true"
android:label="@string/debug_info_title">
</activity>
<activity
android:name=".ui.setup.LoginActivity"
android:label="@string/login_title"
android:parentActivityName=".ui.AccountsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
<activity
android:name=".ui.settings.SettingsActivity"
android:label="@string/settings_title">
<intent-filter>
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
......
/*
* Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.davdroid.ui;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import java.io.IOException;
import at.bitfire.davdroid.Constants;
import at.bitfire.davdroid.R;
public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenuItemClickListener {
public static final String EXTRA_ACCOUNT_NAME = "account_name";
Account account;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String accountName = getIntent().getStringExtra(EXTRA_ACCOUNT_NAME);
if (accountName == null)
// invalid account name
finish();
account = new Account(accountName, Constants.ACCOUNT_TYPE);
setTitle(accountName);
setContentView(R.layout.activity_account);
Toolbar toolbar = (Toolbar)findViewById(R.id.carddav_menu);
toolbar.inflateMenu(R.menu.carddav_actions);
toolbar.setOnMenuItemClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_account, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.delete_account:
DialogFragment frag = new DialogFragment() {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(AccountActivity.this)
.setIcon(R.drawable.ic_error_dark)
.setTitle(R.string.account_delete_confirmation_title)
.setMessage(R.string.account_delete_confirmation_text)
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
deleteAccount();
}
})
.create();
}
};
frag.show(getSupportFragmentManager(), null);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
@Override
public boolean onMenuItemClick(MenuItem item) {
return false;
}
protected void deleteAccount() {
AccountManager accountManager = AccountManager.get(this);
if (Build.VERSION.SDK_INT >= 22)
accountManager.removeAccount(account, this, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
try {
if (future.getResult().getBoolean(AccountManager.KEY_BOOLEAN_RESULT))
finish();
} catch(OperationCanceledException|IOException|AuthenticatorException e) {
Constants.log.error("Couldn't remove account", e);
}
}
}, null);
else
accountManager.removeAccount(account, new AccountManagerCallback<Boolean>() {
@Override
public void run(AccountManagerFuture<Boolean> future) {
try {
if (future.getResult())
finish();
} catch (OperationCanceledException|IOException|AuthenticatorException e) {
Constants.log.error("Couldn't remove account", e);
}
}
}, null);
}
}
......@@ -12,6 +12,7 @@ import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.OnAccountsUpdateListener;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
......@@ -22,7 +23,10 @@ import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.LinkedList;
......@@ -35,7 +39,7 @@ import at.bitfire.davdroid.syncadapter.ServiceDB.*;
import lombok.Cleanup;
import lombok.RequiredArgsConstructor;
public class AccountListFragment extends ListFragment implements OnAccountsUpdateListener, LoaderManager.LoaderCallbacks<List<AccountListFragment.AccountInfo>> {
public class AccountListFragment extends ListFragment implements OnAccountsUpdateListener, LoaderManager.LoaderCallbacks<List<AccountListFragment.AccountInfo>>, AdapterView.OnItemClickListener {
protected AccountManager accountManager;
......@@ -53,6 +57,10 @@ public class AccountListFragment extends ListFragment implements OnAccountsUpdat
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getLoaderManager().initLoader(0, getArguments(), this);
ListView list = getListView();
list.setOnItemClickListener(this);
list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
}
@Override
......@@ -61,6 +69,17 @@ public class AccountListFragment extends ListFragment implements OnAccountsUpdat
super.onDestroyView();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AccountInfo info = (AccountInfo)getListAdapter().getItem(position);
Intent intent = new Intent(getContext(), AccountActivity.class);
intent.putExtra(AccountActivity.EXTRA_ACCOUNT_NAME, info.account.name);
startActivity(intent);
}
@Override
public void onAccountsUpdated(Account[] accounts) {
getLoaderManager().restartLoader(0, null, this);
......@@ -91,6 +110,7 @@ public class AccountListFragment extends ListFragment implements OnAccountsUpdat
boolean hasCardDAV, hasCalDAV;
}
static class AccountListAdapter extends ArrayAdapter<AccountInfo> {
public AccountListAdapter(Context context) {
......@@ -119,6 +139,7 @@ public class AccountListFragment extends ListFragment implements OnAccountsUpdat
return v;
}
}
static class AccountLoader extends AsyncTaskLoader<List<AccountInfo>> {
......
......@@ -59,7 +59,7 @@ public class DebugInfoActivity extends AppCompatActivity implements LoaderManage
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.debug_info_activity);
setContentView(R.layout.activity_debug_info);
tvReport = (TextView)findViewById(R.id.text_report);
getLoaderManager().initLoader(0, getIntent().getExtras(), this);
......
......@@ -28,7 +28,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import at.bitfire.davdroid.R;
import at.bitfire.davdroid.ui.EditPassword;
import at.bitfire.davdroid.ui.widget.EditPassword;
import lombok.Data;
public class LoginCredentialsFragment extends Fragment implements CompoundButton.OnCheckedChangeListener {
......
......@@ -6,7 +6,7 @@
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.davdroid.ui;
package at.bitfire.davdroid.ui.widget;
import android.content.Context;
import android.support.v7.widget.AppCompatCheckBox;
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
~ All rights reserved. This program and the accompanying materials
~ are made available under the terms of the GNU Public License v3.0
~ which accompanies this distribution, and is available at
~ http://www.gnu.org/licenses/gpl.html
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00ffffff"/>
<stroke android:width="1dp"
android:color="#aa888888"
/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"
/>
<corners android:bottomRightRadius="8dp" android:bottomLeftRadius="8dp"
android:topLeftRadius="8dp" android:topRightRadius="8dp"/>
</shape>
\ No newline at end of file
<!--
~ Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
~ All rights reserved. This program and the accompanying materials
~ are made available under the terms of the GNU Public License v3.0
~ which accompanies this distribution, and is available at
~ http://www.gnu.org/licenses/gpl.html
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M16,11c1.66,0 2.99,-1.34 2.99,-3S17.66,5 16,5c-1.66,0 -3,1.34 -3,3s1.34,3 3,3zm-8,0c1.66,0 2.99,-1.34 2.99,-3S9.66,5 8,5C6.34,5 5,6.34 5,8s1.34,3 3,3zm0,2c-2.33,0 -7,1.17 -7,3.5V19h14v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5zm8,0c-0.29,0 -0.62,0.02 -0.97,0.05 1.16,0.84 1.97,1.97 1.97,3.45V19h6v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5z"/>
</vector>
......@@ -12,8 +12,8 @@
android:layout_height="match_parent">
<ImageView
android:src="@drawable/gletschersee"
android:scaleType="centerCrop"
android:src="@drawable/blue_sky_with_birds"
android:scaleType="fitCenter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" />
......@@ -22,6 +22,7 @@
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:divider="@android:color/transparent"
android:background="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"/>
......@@ -30,10 +31,8 @@
android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="72dp"
android:layout_marginRight="64dp"
android:layout_margin="16dp"
android:gravity="center"
android:textColor="@color/white"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="@string/account_list_empty" />
......
......@@ -5,13 +5,13 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
android:gravity="center_horizontal"
android:descendantFocusability="blocksDescendants">
<android.support.v7.widget.CardView
style="@style/account_list_card"
android:layout_margin="16dp"
android:layout_margin="8dp"
android:layout_height="wrap_content"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
card_view:contentPadding="16dp"
card_view:cardBackgroundColor="#ececec"
......@@ -22,21 +22,43 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/carddav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CardDAV"/>
<TextView
android:id="@+id/caldav"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CalDAV"/>
android:gravity="right|center_vertical">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
style="@android:style/Widget.ProgressBar.Small"/>
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:id="@+id/carddav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/chip"
android:text="CardDAV"/>
<TextView
android:id="@+id/caldav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
style="@style/chip"
android:text="CalDAV"/>
</LinearLayout>
<TextView
android:id="@+id/account_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/carddav"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
tools:text="Account Name"/>
......
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
~ All rights reserved. This program and the accompanying materials
~ are made available under the terms of the GNU Public License v3.0
~ which accompanies this distribution, and is available at
~ http://www.gnu.org/licenses/gpl.html
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="8dp"
>
<android.support.v7.widget.Toolbar
android:id="@+id/carddav_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/toolbar_theme"
style="@style/toolbar_style"
app:navigationIcon="@drawable/ic_people_light"
app:title="CardDAV"/>
</android.support.v7.widget.CardView>
</LinearLayout>
\ No newline at end of file
......@@ -56,7 +56,7 @@
android:layout_height="wrap_content"
android:hint="@string/login_email_address"
android:inputType="textEmailAddress"/>
<at.bitfire.davdroid.ui.EditPassword
<at.bitfire.davdroid.ui.widget.EditPassword
android:id="@+id/email_password"
android:hint="@string/login_password"
android:layout_width="match_parent"
......@@ -90,7 +90,7 @@
android:layout_height="wrap_content"
android:hint="@string/login_user_name"
android:inputType="textEmailAddress"/>
<at.bitfire.davdroid.ui.EditPassword
<at.bitfire.davdroid.ui.widget.EditPassword
android:id="@+id/url_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
~ All rights reserved. This program and the accompanying materials
~ are made available under the terms of the GNU Public License v3.0
~ which accompanies this distribution, and is available at
~ http://www.gnu.org/licenses/gpl.html
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/delete_account"
android:title="@string/account_delete"/>
</menu>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
~ All rights reserved. This program and the accompanying materials
~ are made available under the terms of the GNU Public License v3.0
~ which accompanies this distribution, and is available at
~ http://www.gnu.org/licenses/gpl.html
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/refresh"
android:title="@string/account_refresh_address_book_list"/>
<item android:id="@+id/add"
android:title="@string/account_add_existing_address_book"/>
<item android:id="@+id/create"
android:title="@string/account_create_new_address_book"/>
</menu>
\ No newline at end of file
......@@ -27,6 +27,14 @@
<string name="account_list_empty">Welcome to DAVdroid!\n\nYou can add a CalDAV/CardDAV account now.</string>
<!-- AccountActivity -->
<string name="account_delete">Delete account</string>
<string name="account_delete_confirmation_title">Really delete account?</string>
<string name="account_delete_confirmation_text">All local copies of address books, calendars and task lists will be deleted.</string>
<string name="account_refresh_address_book_list">Refresh address book list</string>
<string name="account_add_existing_address_book">Add existing address book</string>
<string name="account_create_new_address_book">Create new address book</string>
<!-- MainActivity -->
<string name="main_manage_accounts">Manage sync accounts</string>
<string name="main_show_debug_info">Show debug info</string>
......
......@@ -65,6 +65,22 @@
</style>
<!-- widgets -->
<style name="chip">
<item name="android:padding">4dp</item>
<item name="android:background">@drawable/chip_bg</item>
</style>
<style name="toolbar_theme">
<item name="android:textColorSecondary">@color/white</item>
</style>
<style name="toolbar_style" parent="Widget.AppCompat.Toolbar">
<item name="android:background">@color/davdroid_green</item>
<item name="titleTextColor">@color/white</item>
</style>
<!-- text content -->
<style name="TextView.Heading" parent="AppTheme">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment