Sfoglia il codice sorgente

move setup call to settings screen

Andy Scherzinger 8 anni fa
parent
commit
4533d5f47f

BIN
res/drawable-hdpi/ic_launch_grey.png


BIN
res/drawable-mdpi/ic_launch_grey.png


BIN
res/drawable-xhdpi/ic_launch_grey.png


BIN
res/drawable-xxhdpi/ic_launch_grey.png


BIN
res/drawable-xxxhdpi/ic_launch_grey.png


+ 0 - 5
res/menu/drawer_menu.xml

@@ -61,11 +61,6 @@
       all items in this group MUST have orderInCategory="3" set
     -->
     <group android:id="@+id/drawer_menu_bottom" android:checkableBehavior="single">
-        <item
-            android:orderInCategory="3"
-            android:id="@+id/nav_dav_client"
-            android:icon="@drawable/ic_launch_grey"
-            android:title="@string/drawer_calendar_contacts"/>
         <item
             android:orderInCategory="3"
             android:id="@+id/nav_settings"

+ 1 - 0
res/values/setup.xml

@@ -56,6 +56,7 @@
     <bool name="multiaccount_support">true</bool>
     
     <!-- Help, imprint and feedback -->
+    <bool name="calendar_contacts_enabled">true</bool>
     <bool name="help_enabled">true</bool>
     <bool name="imprint_enabled">false</bool> 
     <bool name="recommend_enabled">true</bool>

+ 4 - 1
res/values/strings.xml

@@ -37,6 +37,10 @@
     <string name="prefs_log_title_history">Logging history</string>
     <string name="prefs_log_summary_history">This shows the recorded logs</string>
     <string name="prefs_log_delete_history_button">Delete history</string>
+    <string name="prefs_calendar_contacts">Setup calendar &amp; contacts sync</string>
+    <string name="prefs_calendar_contacts_summary">Setup DAVdroid (>v1.3.0) for currently used account</string>
+    <string name="prefs_calendar_contacts_address_resolve_error">Server address for account could not be resolved for DAVdroid</string>
+    <string name="prefs_calendar_contacts_no_store_error">No Google Play store or F-Droid app installed</string>
     <string name="prefs_help">Help</string>
     <string name="prefs_recommend">Recommend to a friend</string>
     <string name="prefs_feedback">Feedback</string>
@@ -353,7 +357,6 @@
     <string name="prefs_category_accounts">Accounts</string>
     <string name="prefs_add_account">Add account</string>
     <string name="drawer_manage_accounts">Manage accounts</string>
-    <string name="drawer_calendar_contacts">Calendar &amp; Contacts</string>
     <string name="auth_redirect_non_secure_connection_title">Secure connection is redirected through an unsecured route.</string>
 
 	<string name="actionbar_logger">Logs</string>

+ 3 - 1
res/xml/preferences.xml

@@ -78,6 +78,9 @@
 	</PreferenceCategory>
 
 	<PreferenceCategory android:title="@string/prefs_category_more" android:key="more">
+		<Preference android:title="@string/prefs_calendar_contacts"
+					android:key="calendar_contacts"
+					android:summary="@string/prefs_calendar_contacts_summary" />
 		<Preference android:title="@string/prefs_help" android:key="help" />
 		<Preference android:title="@string/prefs_recommend" android:key="recommend" />
 		<Preference android:title="@string/prefs_feedback" android:key="feedback" />
@@ -86,5 +89,4 @@
 		<Preference android:title="@string/about_title" android:id="@+id/about_app" android:key="about_app" />
 	</PreferenceCategory>
 
-
 </PreferenceScreen>

+ 0 - 72
src/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -25,12 +25,9 @@ package com.owncloud.android.ui.activity;
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.accounts.AccountManagerFuture;
-import android.accounts.AuthenticatorException;
-import android.accounts.OperationCanceledException;
 import android.content.Intent;
 import android.content.res.Configuration;
 import android.graphics.drawable.Drawable;
-import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.support.design.widget.NavigationView;
@@ -44,14 +41,12 @@ import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.ProgressBar;
 import android.widget.TextView;
-import android.widget.Toast;
 
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.OwnCloudAccount;
-import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
@@ -59,8 +54,6 @@ import com.owncloud.android.lib.resources.users.RemoteGetUserQuotaOperation;
 import com.owncloud.android.ui.TextDrawable;
 import com.owncloud.android.utils.DisplayUtils;
 
-import java.io.IOException;
-
 /**
  * Base class to handle setup of the drawer implementation including user switching and avatar fetching and fallback
  * generation.
@@ -147,10 +140,6 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
      * text view of the quota view.
      */
     private TextView mQuotaTextView;
-    /**
-     * The user's server base uri.
-     */
-    private Uri mUri;
 
     /**
      * Initializes the drawer, its content and highlights the menu item with the given id.
@@ -278,15 +267,6 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
                                 uploadListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                 startActivity(uploadListIntent);
                                 break;
-                            case R.id.nav_dav_client:
-                                try {
-                                    launchDavDroidLogin();
-                                } catch (Throwable t) {
-                                    Log_OC.e(TAG, "Base Uri for account could not be resolved to call DAVdroid!", t);
-                                    // TODO create string resource
-                                    Toast.makeText(MainApp.getAppContext(), "TODO - Base Uri for account could not be resolved to call DAVdroid!", Toast.LENGTH_SHORT).show();
-                                }
-                                break;
                             case R.id.nav_settings:
                                 Intent settingsIntent = new Intent(getApplicationContext(), Preferences.class);
                                 startActivity(settingsIntent);
@@ -323,38 +303,6 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
         }
     }
 
-    private void launchDavDroidLogin()
-            throws com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException,
-            OperationCanceledException,
-            AuthenticatorException,
-            IOException {
-        Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
-
-        Intent davDroidLoginIntent = new Intent();
-        davDroidLoginIntent.setClassName("at.bitfire.davdroid", "at.bitfire.davdroid.ui.setup.LoginActivity");
-        if (getPackageManager().resolveActivity(davDroidLoginIntent, 0) != null) {
-            // arguments
-            if(mUri!=null) {
-                davDroidLoginIntent.putExtra("url", mUri.toString());
-            }
-            davDroidLoginIntent.putExtra("username", AccountUtils.getAccountUsername(account.name));
-            //loginIntent.putExtra("password", "12345");
-            startActivity(davDroidLoginIntent);
-        } else {
-            // DAVdroid not installed
-            Intent installIntent = new Intent(Intent.ACTION_VIEW,
-                    Uri.parse("market://details?id=at.bitfire.davdroid"));
-            if (installIntent.resolveActivity(getPackageManager()) != null) {
-                startActivity(installIntent);
-            } else {
-                // show error message:
-                // "no market available (e.g. custom ROM without Play Store and F-Droid)"
-                // TODO show markets popup for DAVdroid
-                Toast.makeText(MainApp.getAppContext(), "TODO show markets popup for DAVdroid", Toast.LENGTH_SHORT).show();
-            }
-        }
-    }
-
     /**
      * show the file list to the user.
      *
@@ -556,9 +504,6 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
                     mCurrentAccountAvatarRadiusDimension, getResources(), getStorageManager(),
                     findNavigationViewChildById(R.id.drawer_current_account));
 
-            // retrieve base uri
-            setupBaseUri();
-
             // check and show quota info if available
             getAndDisplayUserQuota();
         }
@@ -638,23 +583,6 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
         }
     }
 
-    private void setupBaseUri() {
-        // retrieve and set user's base URI
-        Thread t = new Thread(new Runnable() {
-            public void run() {
-                try {
-                    Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
-                    OwnCloudAccount ocAccount = new OwnCloudAccount(account, MainApp.getAppContext());
-                    mUri = OwnCloudClientManagerFactory.getDefaultSingleton().
-                            getClientFor(ocAccount, getApplicationContext()).getBaseUri();
-                } catch (Throwable t) {
-
-                }
-            }
-        });
-        t.start();
-    }
-
     /**
      * Retrieves and shows the user quota if available
      */

+ 96 - 0
src/com/owncloud/android/ui/activity/Preferences.java

@@ -22,6 +22,8 @@
 package com.owncloud.android.ui.activity;
 
 import android.accounts.Account;
+import android.accounts.AuthenticatorException;
+import android.accounts.OperationCanceledException;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.pm.PackageInfo;
@@ -49,12 +51,17 @@ import android.view.ViewGroup;
 import android.widget.Toast;
 
 import com.owncloud.android.BuildConfig;
+import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.lib.common.OwnCloudAccount;
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.utils.DisplayUtils;
 
+import java.io.IOException;
+
 
 /**
  * An Activity that allows the user to change the application's settings.
@@ -71,6 +78,11 @@ public class Preferences extends PreferenceActivity {
     private static final int ACTION_REQUEST_PASSCODE = 5;
     private static final int ACTION_CONFIRM_PASSCODE = 6;
 
+    /**
+     * The user's server base uri.
+     */
+    private Uri mUri;
+
     private CheckBoxPreference pCode;
     private Preference pAboutApp;
     private AppCompatDelegate mDelegate;
@@ -103,6 +115,9 @@ public class Preferences extends PreferenceActivity {
         actionBar.setDisplayHomeAsUpEnabled(true);
         actionBar.setTitle(R.string.actionbar_settings);
 
+        // retrieve user's base uri
+        setupBaseUri();
+
         // For adding content description tag to a title field in the action bar
         int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
         View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
@@ -148,6 +163,31 @@ public class Preferences extends PreferenceActivity {
         }
 
         PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("more");
+
+        boolean calendarContactsEnabled = getResources().getBoolean(R.bool.calendar_contacts_enabled);
+        Preference pCalendarContacts = findPreference("calendar_contacts");
+        if (pCalendarContacts != null) {
+            if (calendarContactsEnabled) {
+                pCalendarContacts.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+                    @Override
+                    public boolean onPreferenceClick(Preference preference) {
+                        try {
+                            launchDavDroidLogin();
+                        } catch (Throwable t) {
+                            Log_OC.e(TAG, "Base Uri for account could not be resolved to call DAVdroid!", t);
+                            Toast.makeText(
+                                    MainApp.getAppContext(),
+                                    R.string.prefs_calendar_contacts_address_resolve_error,
+                                    Toast.LENGTH_SHORT)
+                                    .show();
+                        }
+                        return true;
+                    }
+                });
+            } else {
+                preferenceCategory.removePreference(pCalendarContacts);
+            }
+        }
         
         boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
         Preference pHelp =  findPreference("help");
@@ -362,6 +402,62 @@ public class Preferences extends PreferenceActivity {
        loadInstantUploadPath();
        loadInstantUploadVideoPath();
     }
+
+    private void launchDavDroidLogin()
+            throws com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException,
+            OperationCanceledException,
+            AuthenticatorException,
+            IOException {
+        Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
+
+        Intent davDroidLoginIntent = new Intent();
+        davDroidLoginIntent.setClassName("at.bitfire.davdroid", "at.bitfire.davdroid.ui.setup.LoginActivity");
+        if (getPackageManager().resolveActivity(davDroidLoginIntent, 0) != null) {
+            // arguments
+            if (mUri != null) {
+                davDroidLoginIntent.putExtra("url", mUri.toString());
+            }
+            davDroidLoginIntent.putExtra("username", AccountUtils.getAccountUsername(account.name));
+            //loginIntent.putExtra("password", "...");
+            startActivity(davDroidLoginIntent);
+        } else {
+            // DAVdroid not installed
+            Intent installIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=at.bitfire.davdroid"));
+
+            // launch market(s)
+            if (installIntent.resolveActivity(getPackageManager()) != null) {
+                startActivity(installIntent);
+            } else {
+                // no f-droid market app or Play store installed --> launch browser for f-droid url
+                Intent downloadIntent = new Intent(Intent.ACTION_VIEW,
+                        Uri.parse("https://f-droid.org/repository/browse/?fdid=at.bitfire.davdroid"));
+                startActivity(downloadIntent);
+
+                Toast.makeText(
+                        MainApp.getAppContext(),
+                        R.string.prefs_calendar_contacts_no_store_error,
+                        Toast.LENGTH_SHORT)
+                        .show();
+            }
+        }
+    }
+
+    private void setupBaseUri() {
+        // retrieve and set user's base URI
+        Thread t = new Thread(new Runnable() {
+            public void run() {
+                try {
+                    Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
+                    OwnCloudAccount ocAccount = new OwnCloudAccount(account, MainApp.getAppContext());
+                    mUri = OwnCloudClientManagerFactory.getDefaultSingleton().
+                            getClientFor(ocAccount, getApplicationContext()).getBaseUri();
+                } catch (Throwable t) {
+                    Log_OC.e(TAG,"Error retrieving user's base URI", t);
+                }
+            }
+        });
+        t.start();
+    }
     
     private void toggleInstantPictureOptions(Boolean value){
         if (value){