move to submodule
This commit is contained in:
parent
0361f9d868
commit
993fa8777d
7 changed files with 0 additions and 494 deletions
|
@ -1,95 +0,0 @@
|
|||
package de.luhmer.owncloudnewsreader;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.View;
|
||||
import android.widget.Checkable;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import de.luhmer.owncloudnewsreader.ListView.AccountImporterAdapter;
|
||||
import de.luhmer.owncloudnewsreader.helper.AccountImporter;
|
||||
import de.luhmer.owncloudnewsreader.interfaces.IAccountImport;
|
||||
|
||||
/**
|
||||
* Created by David on 16.05.2014.
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public class ImportAccountsDialogFragment extends DialogFragment {
|
||||
|
||||
public IAccountImport accountImport;
|
||||
|
||||
static ImportAccountsDialogFragment newInstance() {
|
||||
return new ImportAccountsDialogFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
View view = getActivity().getLayoutInflater().inflate(R.layout.import_accounts_fragment, null);
|
||||
ButterKnife.inject(this, view);
|
||||
|
||||
accountImport = LoginDialogFragment.getInstance();
|
||||
|
||||
|
||||
final List<Account> accounts = AccountImporter.findAccounts(getActivity());
|
||||
List<AccountImporterAdapter.SingleAccount> accountList = new ArrayList<AccountImporterAdapter.SingleAccount>();
|
||||
for(Account account : accounts)
|
||||
accountList.add(new AccountImporterAdapter.SingleAccount(account.type, account.name, false));
|
||||
|
||||
//lvAccounts.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.simple_list_item_single_choice, accountNames));
|
||||
lvAccounts.setAdapter(new AccountImporterAdapter(getActivity(), accountList.toArray(new AccountImporterAdapter.SingleAccount[accountList.size()]), lvAccounts));
|
||||
|
||||
lvAccounts.setItemsCanFocus(false);
|
||||
lvAccounts.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||
|
||||
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setView(view)
|
||||
.setTitle(R.string.import_account_dialog_title)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int x) {
|
||||
|
||||
for (int i = 0; i < lvAccounts.getAdapter().getCount(); i++) {
|
||||
if (lvAccounts.getChildAt(i) instanceof Checkable && ((Checkable) lvAccounts.getChildAt(i)).isChecked()) {
|
||||
|
||||
AccountImporter.getAuthTokenForAccount(getActivity(), accounts.get(i), accountImport);
|
||||
|
||||
/*
|
||||
Intent intent = new Intent(getActivity(), LoginActivity.class);
|
||||
//intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
intent.putExtra(LoginActivity.NEW_ACCOUNT, true);
|
||||
intent.putExtra(URL_STRING, calendars.get(i));
|
||||
intent.putExtra(USERNAME_STRING, username);
|
||||
intent.putExtra(PASSWORD_STRING, password);
|
||||
startActivity(intent);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.create();
|
||||
}
|
||||
|
||||
|
||||
@InjectView(R.id.lvAccounts) ListView lvAccounts;
|
||||
//@InjectView(R.id.pbProgress) ProgressBar pbProgress;
|
||||
|
||||
static final Pattern RemoveAllDoubleSlashes = Pattern.compile("(?<!:)\\/\\/");
|
||||
public static String validateURL(String url) {
|
||||
return RemoveAllDoubleSlashes.matcher(url).replaceAll("/");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
package de.luhmer.owncloudnewsreader.ListView;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import de.luhmer.owncloudnewsreader.R;
|
||||
import de.luhmer.owncloudnewsreader.helper.CheckableLinearLayout;
|
||||
|
||||
/**
|
||||
* Created by David on 29.05.2014.
|
||||
*/
|
||||
public class AccountImporterAdapter extends ArrayAdapter<AccountImporterAdapter.SingleAccount> implements AdapterView.OnItemClickListener {
|
||||
|
||||
Context context;
|
||||
//SingleAccount[] accounts;
|
||||
LayoutInflater inflater;
|
||||
|
||||
public AccountImporterAdapter(Activity context, SingleAccount[] accounts, ListView listView) {
|
||||
super(context, R.layout.simple_list_item_single_choice, accounts);
|
||||
this.context = context;
|
||||
|
||||
listView.setOnItemClickListener(this);
|
||||
|
||||
inflater = context.getLayoutInflater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View view, ViewGroup parent) {
|
||||
ViewHolder holder;
|
||||
|
||||
if (view != null) {
|
||||
holder = (ViewHolder) view.getTag();
|
||||
} else {
|
||||
view = inflater.inflate(R.layout.simple_list_item_single_choice, parent, false);
|
||||
holder = new ViewHolder(view);
|
||||
|
||||
/*
|
||||
holder.cbChecked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if(compoundButton.isChecked()) {
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
getItem(i).checked = false;
|
||||
}
|
||||
getItem(position).checked = true;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
view.setTag(holder);
|
||||
}
|
||||
|
||||
holder.text1.setText(getItem(position).type);
|
||||
holder.text2.setText(getItem(position).url);
|
||||
holder.cbChecked.setChecked(getItem(position).checked);
|
||||
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int id, long l) {
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
getItem(i).checked = false;
|
||||
}
|
||||
((CheckableLinearLayout)view).toggle();
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static class ViewHolder {
|
||||
@InjectView(R.id.text1) TextView text1;
|
||||
@InjectView(R.id.text2) TextView text2;
|
||||
@InjectView(R.id.checkbox) CheckBox cbChecked;
|
||||
|
||||
public ViewHolder(View view) {
|
||||
ButterKnife.inject(this, view);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static class SingleAccount {
|
||||
|
||||
public SingleAccount(String type, String url, Boolean checked) {
|
||||
this.type = type;
|
||||
this.url = url;
|
||||
this.checked = checked;
|
||||
}
|
||||
|
||||
public String type;
|
||||
public String url;
|
||||
|
||||
public boolean checked;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
package de.luhmer.owncloudnewsreader.helper;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AccountManagerCallback;
|
||||
import android.accounts.AccountManagerFuture;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.interfaces.IAccountImport;
|
||||
|
||||
/**
|
||||
* Created by david on 28.05.14.
|
||||
*/
|
||||
public class AccountImporter {
|
||||
|
||||
public static List<Account> findAccounts(Activity activity) {
|
||||
final AccountManager accMgr = AccountManager.get(activity);
|
||||
final Account[] accounts = accMgr.getAccounts();
|
||||
|
||||
List<Account> accountsAvailable = new ArrayList<Account>();
|
||||
for (Account account : accounts) {
|
||||
String aType = account.type.intern();
|
||||
|
||||
if (//aType.equals("org.dmfs.caldav.account") ||
|
||||
// aType.equals("org.dmfs.carddav.account") ||
|
||||
aType.equals("de.luhmer.tasksync") ||
|
||||
aType.equals("owncloud")) {
|
||||
//accountsAvailable.add(accounts[index].type);
|
||||
accountsAvailable.add(account);
|
||||
}
|
||||
}
|
||||
|
||||
return accountsAvailable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void getAuthTokenForAccount(Activity activity, final Account account, final IAccountImport accountImport) {
|
||||
|
||||
|
||||
final AccountManager accMgr = AccountManager.get(activity);
|
||||
/*
|
||||
accMgr.getAuthToken(account, AccountGeneral.ACCOUNT_TYPE, null, activity, new AccountManagerCallback<Bundle>() {
|
||||
public void run(AccountManagerFuture<Bundle> future) {
|
||||
try {
|
||||
// If the user has authorized your application to use the tasks API
|
||||
// a token is available.
|
||||
String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
|
||||
// Now you can use the Tasks API...
|
||||
if(accountImport != null) {
|
||||
accountImport.accountAccessGranted(account, token);
|
||||
}
|
||||
} catch (OperationCanceledException e) {
|
||||
e.printStackTrace();
|
||||
// TODO: The user has denied you access to the API, you should handle that
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
if(accountImport != null) {
|
||||
accountImport.accountAccessGranted(account, null);
|
||||
}
|
||||
*/
|
||||
|
||||
//accMgr.invalidateAuthToken(account.type, AccountGeneral.ACCOUNT_TYPE);
|
||||
//accMgr.invalidateAuthToken(account.type, null);
|
||||
|
||||
final AlertDialog aDialog = new AlertDialog.Builder(activity)
|
||||
.setTitle("Account Importer")
|
||||
.setMessage("Please grant access to the selected account in the notification bar!")
|
||||
.create();
|
||||
|
||||
aDialog.show();
|
||||
|
||||
String authTokenType;
|
||||
if(account.type.equals("owncloud")) {
|
||||
authTokenType = "owncloud.password";
|
||||
} else {
|
||||
authTokenType = "de.luhmer.tasksync";
|
||||
}
|
||||
|
||||
|
||||
final Handler handler = new Handler();
|
||||
accMgr.getAuthToken(account, authTokenType, true,
|
||||
new AccountManagerCallback<Bundle>() {
|
||||
|
||||
@Override
|
||||
public void run(AccountManagerFuture<Bundle> future) {
|
||||
|
||||
try {
|
||||
// If the user has authorized your application to use the tasks API
|
||||
// a token is available.
|
||||
//String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
|
||||
// Now you can use the Tasks API...
|
||||
if(accountImport != null) {
|
||||
accountImport.accountAccessGranted(account, future.getResult());
|
||||
}
|
||||
} catch (OperationCanceledException e) {
|
||||
e.printStackTrace();
|
||||
// TODO: The user has denied you access to the API, you should handle that
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
aDialog.dismiss();
|
||||
|
||||
}
|
||||
}, handler
|
||||
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package de.luhmer.owncloudnewsreader.helper;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Checkable;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
/**
|
||||
* Created by David on 29.05.2014.
|
||||
*/
|
||||
|
||||
public class CheckableLinearLayout extends LinearLayout implements Checkable {
|
||||
private CheckBox _checkbox;
|
||||
|
||||
public CheckableLinearLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
// find checked text view
|
||||
int childCount = getChildCount();
|
||||
for (int i = 0; i < childCount; ++i) {
|
||||
View v = getChildAt(i);
|
||||
if (v instanceof CheckBox) {
|
||||
_checkbox = (CheckBox)v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return _checkbox != null ? _checkbox.isChecked() : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChecked(boolean checked) {
|
||||
if (_checkbox != null) {
|
||||
_checkbox.setChecked(checked);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggle() {
|
||||
if (_checkbox != null) {
|
||||
_checkbox.toggle();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package de.luhmer.owncloudnewsreader.interfaces;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* Created by David on 28.05.2014.
|
||||
*/
|
||||
public interface IAccountImport {
|
||||
public void accountAccessGranted(Account account, Bundle data);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
<ListView
|
||||
android:id="@+id/lvAccounts"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
|
||||
<!--
|
||||
<ProgressBar
|
||||
android:id="@+id/pbProgress"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
-->
|
||||
</LinearLayout>
|
|
@ -1,74 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2008 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<de.luhmer.owncloudnewsreader.helper.CheckableLinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_margin="5dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1"
|
||||
android:text="dahsjkfasd"
|
||||
android:textSize="17dp"
|
||||
android:gravity="center_vertical" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1"
|
||||
android:text="dsfjhkafadsjhkas@fdsjfk hld lfdhsjkfldh sajkflh jdaskfhjdkla sfhjdksla fhl"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="middle"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="15dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:focusable="false"/>
|
||||
|
||||
</de.luhmer.owncloudnewsreader.helper.CheckableLinearLayout>
|
||||
|
||||
<!--
|
||||
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@android:id/text1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/listPreferredItemHeightSmall"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSmall"
|
||||
android:gravity="center_vertical"
|
||||
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="marquee"
|
||||
/>
|
||||
-->
|
Loading…
Reference in a new issue