diff --git a/ACalDAV/res/values-da/strings.xml b/ACalDAV/res/values-da/strings.xml index 771e2ac..415337a 100644 --- a/ACalDAV/res/values-da/strings.xml +++ b/ACalDAV/res/values-da/strings.xml @@ -47,4 +47,6 @@ Gem I dag Placering + Server (valgfri) + > Login \ No newline at end of file diff --git a/ACalDAV/res/values-de/strings.xml b/ACalDAV/res/values-de/strings.xml index ae55a98..5f07360 100644 --- a/ACalDAV/res/values-de/strings.xml +++ b/ACalDAV/res/values-de/strings.xml @@ -51,5 +51,7 @@ Speichern Heute Standort + Server (optional) + > Anmelden \ No newline at end of file diff --git a/ACalDAV/res/values-el/strings.xml b/ACalDAV/res/values-el/strings.xml index 0f37554..1a69c6c 100644 --- a/ACalDAV/res/values-el/strings.xml +++ b/ACalDAV/res/values-el/strings.xml @@ -47,4 +47,6 @@ Αποθήκευση Σήμερα Τοποθεσία + Διακομιστής (προαιρετικός) + > Σύνδεση \ No newline at end of file diff --git a/ACalDAV/res/values-es/strings.xml b/ACalDAV/res/values-es/strings.xml index 0f3e40f..8363bd3 100644 --- a/ACalDAV/res/values-es/strings.xml +++ b/ACalDAV/res/values-es/strings.xml @@ -47,4 +47,6 @@ Guardar Hoy Ubicación + Servidor (opcional) + > Inicio de sesión \ No newline at end of file diff --git a/ACalDAV/res/values-fi/strings.xml b/ACalDAV/res/values-fi/strings.xml index b95fd6f..3908c58 100644 --- a/ACalDAV/res/values-fi/strings.xml +++ b/ACalDAV/res/values-fi/strings.xml @@ -47,4 +47,6 @@ Tallenna Tänään Sijainti + Palvelin (valinnainen) + > Kirjautuminen \ No newline at end of file diff --git a/ACalDAV/res/values-fr/strings.xml b/ACalDAV/res/values-fr/strings.xml index f2f7c72..8f168f5 100644 --- a/ACalDAV/res/values-fr/strings.xml +++ b/ACalDAV/res/values-fr/strings.xml @@ -47,4 +47,6 @@ Sauvegarder Aujourd\'hui Localisation + Serveur (optionnel) + > Connexion \ No newline at end of file diff --git a/ACalDAV/res/values-it/strings.xml b/ACalDAV/res/values-it/strings.xml index abb4778..81d05eb 100644 --- a/ACalDAV/res/values-it/strings.xml +++ b/ACalDAV/res/values-it/strings.xml @@ -48,4 +48,6 @@ Salva Oggi Posizione + Server (opzionale) + > Accedi \ No newline at end of file diff --git a/ACalDAV/res/values-iw/strings.xml b/ACalDAV/res/values-iw/strings.xml index 304fe03..66c2d62 100644 --- a/ACalDAV/res/values-iw/strings.xml +++ b/ACalDAV/res/values-iw/strings.xml @@ -37,4 +37,6 @@ היום מקום (ללא כותרת) + שרת (אופציונלי) + > התחבר \ No newline at end of file diff --git a/ACalDAV/res/values-ja/strings.xml b/ACalDAV/res/values-ja/strings.xml index 1182632..93dd13c 100644 --- a/ACalDAV/res/values-ja/strings.xml +++ b/ACalDAV/res/values-ja/strings.xml @@ -47,4 +47,6 @@ 保存 今日 場所 + サーバー (オプション) + > ログイン \ No newline at end of file diff --git a/ACalDAV/res/values-nb-rNO/strings.xml b/ACalDAV/res/values-nb-rNO/strings.xml index ceb6dd7..8b5ab48 100644 --- a/ACalDAV/res/values-nb-rNO/strings.xml +++ b/ACalDAV/res/values-nb-rNO/strings.xml @@ -47,4 +47,6 @@ Lagre I dag Sted + Server (valgfritt) + > Logg inn \ No newline at end of file diff --git a/ACalDAV/res/values-nl/strings.xml b/ACalDAV/res/values-nl/strings.xml index e33cbf5..613660c 100644 --- a/ACalDAV/res/values-nl/strings.xml +++ b/ACalDAV/res/values-nl/strings.xml @@ -47,4 +47,6 @@ Opslaan Vandaag Plaats + Server (optioneel) + > Inloggen \ No newline at end of file diff --git a/ACalDAV/res/values-no/strings.xml b/ACalDAV/res/values-no/strings.xml index 9a44e5e..8f1be7a 100644 --- a/ACalDAV/res/values-no/strings.xml +++ b/ACalDAV/res/values-no/strings.xml @@ -47,4 +47,6 @@ Lagre I dag Sted + Server (valgfritt) + > Logg inn \ No newline at end of file diff --git a/ACalDAV/res/values-ru/strings.xml b/ACalDAV/res/values-ru/strings.xml index 031deff..4a57723 100644 --- a/ACalDAV/res/values-ru/strings.xml +++ b/ACalDAV/res/values-ru/strings.xml @@ -47,4 +47,6 @@ Сохранить Сегодня Местоположение + Сервер (необязательно) + > Вход в систему \ No newline at end of file diff --git a/ACalDAV/res/values-sv/strings.xml b/ACalDAV/res/values-sv/strings.xml index 5f97d0c..469fd16 100644 --- a/ACalDAV/res/values-sv/strings.xml +++ b/ACalDAV/res/values-sv/strings.xml @@ -47,4 +47,6 @@ Spara Idag Plats + Server (valfritt) + > Inloggning \ No newline at end of file diff --git a/ACalDAV/res/values/strings.xml b/ACalDAV/res/values/strings.xml index 6bc2346..aedd74a 100644 --- a/ACalDAV/res/values/strings.xml +++ b/ACalDAV/res/values/strings.xml @@ -60,6 +60,8 @@ Location (No title) + Server (optional) + > Login \ No newline at end of file diff --git a/ACalDAV/src/com/android/common/LoginActivity.java b/ACalDAV/src/com/android/common/LoginActivity.java index cf33f12..c749715 100644 --- a/ACalDAV/src/com/android/common/LoginActivity.java +++ b/ACalDAV/src/com/android/common/LoginActivity.java @@ -55,13 +55,17 @@ protected void onCreate(Bundle savedInstanceState) { mPosition = getIntent().getIntExtra("position", 0); mName = getIntent().getStringExtra("name"); mValue = getIntent().getStringExtra("value"); + if (mValue == null) { if ((mPosition == 0 && !getString(R.string.email_label).equals(mName)) || (mPosition == 1 && !getString(R.string.password_label).equals(mName))) { mValue = mName; } else if (mPosition == 1 && !getString(R.string.password_label).equals(mName)) { mValue = mName; + } else if (mPosition == 2 && !getString(R.string.custom_server_label).equals(mName)) { + mValue = mName; } + } mRcContent = findViewById(R.id.rv_content_login); @@ -224,12 +228,16 @@ public void onBindViewHolder(@NonNull final MyHolder holder, int position) { requestFocus(mSaveText); } else if (position == 1) { mLoginText = holder.mView.findViewById(R.id.login_text); - mLoginText.setText(mPosition == 0 ? getString(R.string.email_label) : getString(R.string.password_label)); mInputText = holder.mView.findViewById(R.id.login_edit); if (mPosition == 0) { + mLoginText.setText(getString(R.string.email_label)); mInputText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS); } else if (mPosition == 1) { + mLoginText.setText(getString(R.string.password_label)); mInputText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); + } else if (mPosition == 2) { + mLoginText.setText(getString(R.string.custom_server_label)); + mInputText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); } mInputText.setText(mValue); if (mValue != null && mValue.length() > 0) { @@ -295,7 +303,17 @@ public void run() { public void itemClick(View view, int position) { if (position == 0) { Intent intent = new Intent(); - intent.putExtra("Name", mPosition == 0 ? getString(R.string.email_label) : getString(R.string.password_label)); + + String name = ""; + if (mPosition == 0) { + name = getString(R.string.email_label); + } else if (mPosition == 1) { + name = getString(R.string.password_label); + } else if (mPosition == 2) { + name = getString(R.string.custom_server_label); + } + + intent.putExtra("Name", name); intent.putExtra("Save", mInputText.getText().toString()); setResult(0, intent); finish(); diff --git a/ACalDAV/src/com/aphy/caldavsyncadapter/Constants.java b/ACalDAV/src/com/aphy/caldavsyncadapter/Constants.java index a3cd450..b7cca1f 100644 --- a/ACalDAV/src/com/aphy/caldavsyncadapter/Constants.java +++ b/ACalDAV/src/com/aphy/caldavsyncadapter/Constants.java @@ -3,4 +3,12 @@ public interface Constants { String USER_DATA_TRUST_ALL_KEY = "USER_DATA_TRUSTALL_KEY"; - String INVALID_CREDENTIALS_CHECK="CREDENTIALS_CHECK";} \ No newline at end of file + String INVALID_CREDENTIALS_CHECK = "CREDENTIALS_CHECK"; + + String APOSTROPHY_DAV_URL = "https://dav.aphy.app"; + + Boolean DEBUG = false; + String DEBUG_SERVER = "http://10.0.2.2:5232/test/f77a0cf2-de01-9ce3-0b31-3d067b740bf9/"; + String DEBUG_USER = "test"; + String DEBUG_PASSWORD = "hello"; +} \ No newline at end of file diff --git a/ACalDAV/src/com/aphy/caldavsyncadapter/android/entities/AccountName.java b/ACalDAV/src/com/aphy/caldavsyncadapter/android/entities/AccountName.java index 379156b..89f38d7 100644 --- a/ACalDAV/src/com/aphy/caldavsyncadapter/android/entities/AccountName.java +++ b/ACalDAV/src/com/aphy/caldavsyncadapter/android/entities/AccountName.java @@ -1,14 +1,20 @@ package com.aphy.caldavsyncadapter.android.entities; +import com.aphy.caldavsyncadapter.Constants; + import java.util.Objects; public class AccountName { public static String AccountName = "AccountName"; public static String Password = "Password"; + public static String ServerURL = "ServerUrl"; + private String mAccountName; private String mPassword; + private String mServerURL; + public String getAccountName() { return mAccountName; } @@ -21,10 +27,18 @@ public String getPassword() { return mPassword; } + public String getServerURL() { + return mServerURL; + } + public void setPassword(String password) { this.mPassword = password; } + public void setServerURL(String serverURL) { + this.mServerURL = serverURL; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -35,7 +49,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - return Objects.hash(mAccountName, mPassword); + return Objects.hash(mAccountName, mPassword, mServerURL); } @Override @@ -43,11 +57,13 @@ public String toString() { return "AccountName{" + "mAccountName='" + mAccountName + '\'' + ", mPassword='" + mPassword + '\'' + + ", mServerURL='" + mServerURL + '\'' + '}'; } public void clearAccountInfo() { mAccountName = ""; mPassword = ""; + mServerURL = ""; } } \ No newline at end of file diff --git a/ACalDAV/src/com/aphy/caldavsyncadapter/authenticator/AuthenticatorActivity.java b/ACalDAV/src/com/aphy/caldavsyncadapter/authenticator/AuthenticatorActivity.java index d3c4a47..5666021 100644 --- a/ACalDAV/src/com/aphy/caldavsyncadapter/authenticator/AuthenticatorActivity.java +++ b/ACalDAV/src/com/aphy/caldavsyncadapter/authenticator/AuthenticatorActivity.java @@ -36,6 +36,7 @@ import com.android.common.LoginActivity; import com.android.common.MenuItem; import com.android.common.MyDecoration; +import com.aphy.caldavsyncadapter.Constants; import com.aphy.caldavsyncadapter.android.entities.AccountName; import com.aphy.caldavsyncadapter.caldav.entities.CalendarEvent; import com.aphy.caldavsyncadapter.caldav.entities.CalendarList; @@ -43,6 +44,7 @@ import org.apache.http.client.ClientProtocolException; import org.apache.http.conn.HttpHostConnectException; + import com.aphy.caldavsyncadapter.android.entities.CalendarEventData; import com.aphy.caldavsyncadapter.caldav.CaldavFacade; import com.aphy.caldavsyncadapter.caldav.CaldavFacade.TestConnectionResult; @@ -99,7 +101,7 @@ public void onCreate(Bundle savedInstanceState, PersistableBundle persistentStat private Context mContext; - private String mURL; + private String mURL = ""; private List mCalendarEventDataList; private List mCalendarEventDataListFromDataBase; @@ -126,8 +128,11 @@ public void onCreate(Bundle savedInstanceState, PersistableBundle persistentStat private AccountName mSyncAccountName; private boolean isSyncNow = false; + private boolean isLoginView = true; private long mRespondTime; + private Toast toastsync = null; + public AuthenticatorActivity() { super(); } @@ -142,7 +147,7 @@ protected void onCreate(Bundle savedInstanceState) { mTextSwitcher = findViewById(R.id.textSwitcher); mTextSwitcher.setFactory(mFactory); isSyncNow = false; - initList(); +// initList(); MenuItem.init(this); myAdaptor = new MyAdaptor(); myAdaptor.setIListItemClick(iListItemClickListener); @@ -161,21 +166,21 @@ private void initUserDB() { getAccountInfo(); if (mSyncAccountName != null && !"".equals(mSyncAccountName.getAccountName()) && !"".equals(mSyncAccountName.getPassword())) { + initList(); mUser = mSyncAccountName.getAccountName(); mPassword = mSyncAccountName.getPassword(); + mURL = mSyncAccountName.getServerURL(); mRecyclerViewList.set(0, getString(R.string.logout_label)); mRecyclerViewList.set(1, getString(R.string.sync_calendar)); mTextSwitcher.setText(mRecyclerViewList.get(0)); mCalendarEventDataListFromDataBase = userDBHelper.queryCal( "DtStart between " + TimeUtil.getTodayStamp() + " and " + TimeUtil.getFourDaysStamp() + " order by DtStart asc"); + isLoginView = false; if (mCalendarEventDataListFromDataBase != null) { updateCalendarList(); } - } else { - mRecyclerViewList.set(0, getString(R.string.email_label)); - mRecyclerViewList.set(1, getString(R.string.password_label)); - mTextSwitcher.setText(mRecyclerViewList.get(0)); - } + } else + initLoginItems(); } private void getAccountInfo() { @@ -185,6 +190,7 @@ private void getAccountInfo() { mSyncAccountName = new AccountName(); mSyncAccountName.setAccountName(accountNameList.get(i).getAccountName()); mSyncAccountName.setPassword(accountNameList.get(i).getPassword()); + mSyncAccountName.setServerURL(accountNameList.get(i).getServerURL()); } } } @@ -216,6 +222,8 @@ public boolean onCreateOptionsMenu(Menu menu) { private void initList() { mRecyclerViewList.add(""); mRecyclerViewList.add(""); + mRecyclerViewList.add(""); + mRecyclerViewList.add(""); } private final ViewFactory mFactory = new ViewFactory() { @@ -382,7 +390,7 @@ public void onClick(View v) { mSparseArray.put(position, holder); - if (!mDataInited && position == 2) { + if (!mDataInited && position == 0) { mHandler.postDelayed(new Runnable() { @Override public void run() { @@ -393,7 +401,7 @@ public void run() { if (mLastPosition != mCurrentIndex) { mLastPosition = mCurrentIndex; } - mTextSwitcher.setText(mRecyclerViewList.get(2)); + mTextSwitcher.setText(mRecyclerViewList.get(0)); } }, 100); } @@ -419,24 +427,26 @@ public int getItemCount() { private IListItemClick iListItemClickListener = new IListItemClick() { @Override public void itemClick(View view, int position) { - String indexStr = mRecyclerViewList.get(position); - if (isEmailPosition(position) || isPasswordPosition(position)) { + String itemStr = getSelectedItemLabel(position); + + if (isLoginView && !getString(R.string.login_btn_label).equals(itemStr)) { Log.i(TAG, "isSyncNow = " + isSyncNow); if (!isSyncNow) { Intent intent = new Intent(); intent.setClass(AuthenticatorActivity.this, LoginActivity.class); intent.putExtra("position", position); - intent.putExtra("name", indexStr); + intent.putExtra("name", itemStr); + if (mSyncAccountName == null) getAccountInfo(); if (mSyncAccountName != null) { - intent.putExtra("value", position == 0 ? mSyncAccountName.getAccountName() : mSyncAccountName.getPassword()); + intent.putExtra("value", getSelectedItemValue(position)); } mCurrentIndexStopped = mCurrentIndex; startActivityForResult(intent, 0); } - } else if (getString(R.string.logout_label).equals(indexStr)) { + } else if (getString(R.string.logout_label).equals(itemStr)) { logout(); - } else if (getString(R.string.sync_calendar).equals(indexStr)) { + } else if (getString(R.string.sync_calendar).equals(itemStr) || getString(R.string.login_btn_label).equals(itemStr)) { attemptLogin(); } else { String datestamp = mDateStampList.get(position - 2); @@ -464,32 +474,89 @@ public void itemClick(View view, int position) { } }; - private boolean isEmailPosition(int position) { - String indexStr = mRecyclerViewList.get(position); - return (position == 0 && !getString(R.string.logout_label).equals(indexStr)); + + private String getSelectedItemLabel(int position) { + return mRecyclerViewList.get(position); } - private boolean isPasswordPosition(int position) { - String indexStr = mRecyclerViewList.get(position); - return (position == 1 && !getString(R.string.sync_calendar).equals(indexStr)); + private String getSelectedItemValue(int position) { + String item = getSelectedItemLabel(position); + if (getString(R.string.email_label).equals(item)) { + return mSyncAccountName.getAccountName(); + } else if (getString(R.string.password_label).equals(item)) { + return mSyncAccountName.getPassword(); + } else if (getString(R.string.custom_server_label).equals(item)) { + return mSyncAccountName.getServerURL(); + } + + return ""; + } + + // TODO: Improve login form validation + private boolean validateForm() { + + return true; + +// String errorText = ""; +// +// if (mURL.equals("")) { +// if (mUser.equals("")) { +// errorText = getString(R.string.error_invalid_email); +// } else if (mPassword.equals("")) { +// errorText = getString(R.string.error_invalid_password); +// } else { +// return true; +// } +// } else { +// return true; +// } +// +// toastsync = Toast +// .makeText(getApplicationContext(), errorText, Toast.LENGTH_SHORT); +// toastsync.show(); +// +// return false; + + } + + private void initLoginItems() { + mRecyclerViewList.clear(); + + if (!Constants.DEBUG) { + mRecyclerViewList.add(getString(R.string.email_label)); + mRecyclerViewList.add(getString(R.string.password_label)); + mRecyclerViewList.add(getString(R.string.custom_server_label)); + mURL = Constants.APOSTROPHY_DAV_URL; + } else { + mRecyclerViewList.add(0, Constants.DEBUG_USER); + mRecyclerViewList.add(1, Constants.DEBUG_PASSWORD); + mRecyclerViewList.add(2, Constants.DEBUG_SERVER); + mUser = Constants.DEBUG_USER; + mPassword = Constants.DEBUG_PASSWORD; + mURL = Constants.DEBUG_SERVER; + } + + mRecyclerViewList.add(getString(R.string.login_btn_label)); + mTextSwitcher.setText(mRecyclerViewList.get(0)); + } + private void logout() { Log.d(TAG, "logout"); mUser = ""; mPassword = ""; + mURL = ""; if (mSyncAccountName != null) { mSyncAccountName.clearAccountInfo(); } userDBHelper.deleteAll(UserDBHelper.TABLE_NAME_ACCOUNT); - mRecyclerViewList.clear(); - mRecyclerViewList.add(getString(R.string.email_label)); - mRecyclerViewList.add(getString(R.string.password_label)); - mTextSwitcher.setText(mRecyclerViewList.get(0)); + initLoginItems(); myAdaptor.notifyDataSetChanged(); mCurrentIndex = 0; mLastPosition = 0; mCurrentIndexStopped = 0; + isLoginView = true; } @SuppressLint("NotifyDataSetChanged") @@ -499,6 +566,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null && resultCode == 0) { String value = data.getExtras().getString("Save"); String name = data.getExtras().getString("Name"); + if (getString(R.string.email_label).equals(name)) { mUser = value; if (!"".equals(value)) { @@ -518,10 +586,17 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { myAdaptor.notifyDataSetChanged(); } } - mTextSwitcher.setText(value); - if (!"".equals(mUser) && !"".equals(mPassword)) { - attemptLogin(); + + if (getString(R.string.custom_server_label).equals(name)) { + mURL = value; + if (!"".equals(value)) { + mRecyclerViewList.set(2, value); + myAdaptor.notifyDataSetChanged(); + } } + + + mTextSwitcher.setText(value); } } @@ -538,6 +613,7 @@ private void notifyLoginSuccess() { myAdaptor.notifyDataSetChanged(); mCurrentIndex = 0; mLastPosition = 0; + isLoginView = false; updateCalendarList(); } @@ -565,9 +641,11 @@ public void attemptLogin() { return; } - Log.i(TAG, "attemptLogin"); + if (!validateForm()) { + return; + } - mURL = "https://dav.aphy.app"; + Log.i(TAG, "attemptLogin"); boolean cancel = false; View focusView = null; @@ -603,7 +681,6 @@ protected enum LoginResult { */ public class UserLoginTask extends AsyncTask { private Activity activity; - private Toast toastsync = null; @Override protected LoginResult doInBackground(Void... params) { @@ -664,6 +741,8 @@ public void run() { AccountName accountName = new AccountName(); accountName.setAccountName(mUser); accountName.setPassword(mPassword); + accountName.setServerURL(mURL); + userDBHelper.insertAccount(accountName); result = TestConnectionResult.SUCCESS; @@ -684,7 +763,7 @@ public void run() { e.printStackTrace(); Log.w(TAG, "CaldavProtocolException = " + e); result = TestConnectionResult.WRONG_ANSWER; - } catch (FileNotFoundException e) { + } catch (FileNotFoundException e) { e.printStackTrace(); Log.w(TAG, "FileNotFoundException = " + e); result = TestConnectionResult.WRONG_URL; @@ -706,11 +785,11 @@ public void run() { e.printStackTrace(); Log.w(TAG, "ParserConfigurationException = " + e); return LoginResult.UnkonwnException; - } catch (UnknownHostException e) { + } catch (UnknownHostException e) { e.printStackTrace(); Log.w(TAG, "UnknownHostException = " + e); return LoginResult.UnknownHostException; - } catch (IOException e) { + } catch (IOException e) { e.printStackTrace(); Log.w(TAG, "IOException = " + e); return LoginResult.UnkonwnException; @@ -759,6 +838,7 @@ protected void onPostExecute(final LoginResult result) { } int duration = Toast.LENGTH_LONG; Toast toast = null; + Log.i(TAG, "result = " + result); switch (result) { case Success_Calendar: diff --git a/ACalDAV/src/com/aphy/caldavsyncadapter/caldav/CaldavFacade.java b/ACalDAV/src/com/aphy/caldavsyncadapter/caldav/CaldavFacade.java index 42e734e..769e3af 100644 --- a/ACalDAV/src/com/aphy/caldavsyncadapter/caldav/CaldavFacade.java +++ b/ACalDAV/src/com/aphy/caldavsyncadapter/caldav/CaldavFacade.java @@ -1,22 +1,21 @@ /** * Copyright (c) 2012-2013, Gerald Garcia, David Wiesner, Timo Berger - * + *

* This file is part of Andoid Caldav Sync Adapter Free. - * - * Andoid Caldav Sync Adapter Free is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of the + *

+ * Andoid Caldav Sync Adapter Free is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the * License, or at your option any later version. - * - * Andoid Caldav Sync Adapter Free is distributed in the hope that - * it will be useful, but WITHOUT ANY WARRANTY; without even the implied + *

+ * Andoid Caldav Sync Adapter Free is distributed in the hope that + * it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License - * along with Andoid Caldav Sync Adapter Free. + * along with Andoid Caldav Sync Adapter Free. * If not, see . - * */ package com.aphy.caldavsyncadapter.caldav; @@ -26,6 +25,7 @@ import android.content.Context; import android.util.Log; +import com.aphy.caldavsyncadapter.Constants; import com.aphy.caldavsyncadapter.caldav.discovery.DefaultDiscoveryStrategy; import com.aphy.caldavsyncadapter.caldav.discovery.DiscoveryStrategy; import com.aphy.caldavsyncadapter.caldav.discovery.GoogleDiscoveryStrategy; @@ -168,9 +168,10 @@ public void process(final HttpRequest request, final HttpContext context) } else { //AuthState and AuthScope have to be saved separate because of the AuthScope within AuthState gets lost, so we save it in a separate var. mLastAuthState = authState; - if (BuildConfig.DEBUG) Log.d(TAG, "LastAuthState: new with user " + mLastAuthState.getCredentials() - .getUserPrincipal() - .getName()); + if (BuildConfig.DEBUG) + Log.d(TAG, "LastAuthState: new with user " + mLastAuthState.getCredentials() + .getUserPrincipal() + .getName()); if (authState.getAuthScope() != null) { mLastAuthScope = authState.getAuthScope(); Log.d(TAG, "LastAuthScope: new"); @@ -197,17 +198,19 @@ public void process(final HttpRequest request, final HttpContext context) private ContentProviderClient mProvider; - private static DiscoveryStrategy discoveryStrategy; - + private static DiscoveryStrategy discoveryStrategy; + private static List discoveryStrategies = Arrays.asList( - new DiscoveryStrategy[] {new GoogleDiscoveryStrategy()}); + new DiscoveryStrategy[]{new GoogleDiscoveryStrategy()}); private static DiscoveryStrategy defaultDiscoveryStrategy = new DefaultDiscoveryStrategy(); public CaldavFacade(String mUser, String mPassword, String mURL, String trustAll) throws MalformedURLException { - if ("https://dav.aphy.app".equals(mURL)) { - mURL = "https://dav.aphy.app/dav/calendars/user/" + mUser + "/Default/"; + + if (Constants.APOSTROPHY_DAV_URL.equals(mURL)) { + mURL = Constants.APOSTROPHY_DAV_URL + "/dav/calendars/user" + mUser + "/Default/"; } + url = new URL(mURL); this.mTrustAll = Boolean.valueOf(trustAll); @@ -253,16 +256,16 @@ public CaldavFacade(String mUser, String mPassword, String mURL, String trustAll } private DiscoveryStrategy resolveDiscoveryStrategy() { - for (DiscoveryStrategy ds : discoveryStrategies) { - if (ds.supportsTargetHost(targetHost)) { - return ds; - } - } - return defaultDiscoveryStrategy; - } - - private static HttpReport createReportRequest(URI uri, String data, int depth) { - return discoveryStrategy.createReportRequest(uri, data, depth, targetHost); + for (DiscoveryStrategy ds : discoveryStrategies) { + if (ds.supportsTargetHost(targetHost)) { + return ds; + } + } + return defaultDiscoveryStrategy; + } + + private static HttpReport createReportRequest(URI uri, String data, int depth) { + return discoveryStrategy.createReportRequest(uri, data, depth, targetHost); } public static void fetchEvent_old(CalendarEvent calendarEvent) @@ -324,7 +327,7 @@ protected HttpClient getHttpClient() { HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); SchemeRegistry registry = new SchemeRegistry(); - registry.register(new Scheme("http", new PlainSocketFactory(), 80)); + registry.register(new Scheme("http", new PlainSocketFactory(), 80)); registry.register(new Scheme("https", (mTrustAll ? EasySSLSocketFactory.getSocketFactory() : new TlsSniSocketFactory()), 443 )); @@ -450,7 +453,7 @@ private List getCalendarHomes(URI userPrincipal) parseXML(response, calendarHomeHandler); List result = calendarHomeHandler.calendarHomeSet; if (BuildConfig.DEBUG) Log.d(TAG, result.size() + " calendar-home-set found in " - + userPrincipal.toString()); + + userPrincipal.toString()); return result; } @@ -559,7 +562,7 @@ public ArrayList getCalendarEvents(DavCalendar calendar) if (BuildConfig.DEBUG) Log.d(TAG, "HttpResponse status=" + response.getStatusLine() - + " body= " + body); + + " body= " + body); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); @@ -668,7 +671,7 @@ private HttpDelete createDeleteRequest(URI uri) { } private HttpPut createPutRequest(URI uri, String data, int depth) { - return discoveryStrategy.createPutRequest(uri, data, depth, targetHost); + return discoveryStrategy.createPutRequest(uri, data, depth, targetHost); } /** @@ -700,7 +703,7 @@ public boolean updateEvent(URI uri, String data, String ETag) { Log.w(TAG, "Unkown StatusCode during creation of an event"); } } catch (ClientProtocolException e) { - Log.e(getLastETag(),e.getMessage()); + Log.e(getLastETag(), e.getMessage()); } catch (IOException e) { Log.e(getLastETag(), e.getMessage()); } catch (AuthenticationException e) { @@ -762,16 +765,16 @@ public boolean deleteEvent(URI calendarEventUri, String ETag) { Log.w(TAG, "Unkown StatusCode during deletion of an event"); } } catch (ClientProtocolException e) { - Log.e(getLastETag(),e.getMessage()); + Log.e(getLastETag(), e.getMessage()); } catch (IOException e) { if (lastStatusCode == 404) { //the event has already been deleted on server side. no action needed lcResult = true; } else { - Log.e(getLastETag(),e.getMessage()); + Log.e(getLastETag(), e.getMessage()); } } catch (AuthenticationException e) { - Log.e(getLastETag(),e.getMessage()); + Log.e(getLastETag(), e.getMessage()); } return lcResult; diff --git a/ACalDAV/src/com/aphy/provider/UserDBHelper.java b/ACalDAV/src/com/aphy/provider/UserDBHelper.java index e279a2c..fb1ba9e 100644 --- a/ACalDAV/src/com/aphy/provider/UserDBHelper.java +++ b/ACalDAV/src/com/aphy/provider/UserDBHelper.java @@ -94,7 +94,8 @@ public void onCreate(SQLiteDatabase db) { String account_sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME_ACCOUNT + "(" + "AccountName VARCHAR," - + "Password VARCHAR" + + "Password VARCHAR," + + "ServerUrl VARCHAR" + ");"; db.execSQL(account_sql); } @@ -231,6 +232,7 @@ public ContentValues getAccountContentValues(AccountName accountName) { ContentValues cv = new ContentValues(); cv.put(AccountName.AccountName, accountName.getAccountName()); cv.put(AccountName.Password, accountName.getPassword()); + cv.put(AccountName.ServerURL, accountName.getServerURL()); return cv; } @@ -245,6 +247,7 @@ public List queryAccount(String condition) { accountName.setAccountName(cursor.getString(cursor.getColumnIndex(AccountName.AccountName))); accountName.setPassword(cursor.getString(cursor.getColumnIndex(AccountName.Password))); + accountName.setServerURL(cursor.getString(cursor.getColumnIndex(AccountName.ServerURL))); infoList.add(accountName); } cursor.close();