Merge with develop
authorMagnus Sjoqvist <magnus.b.j.sjoqvist@gmail.com>
Fri, 17 Oct 2014 09:06:30 +0000 (11:06 +0200)
committerMagnus Sjoqvist <magnus.b.j.sjoqvist@gmail.com>
Fri, 17 Oct 2014 09:06:30 +0000 (11:06 +0200)
res/values-it/strings.xml
res/values-sv/strings.xml
res/values/strings.xml
res/xml/preferences.xml
src/com/owncloud/android/ui/activity/Preferences.java
src/com/owncloud/android/ui/activity/Uploader.java

index d450760..7423cbf 100644 (file)
@@ -30,6 +30,8 @@
   <string name="prefs_recommend">Consiglia ad un amico</string>
   <string name="prefs_feedback">Segnalazioni</string>
   <string name="prefs_imprint">Imprint</string>
+  <string name="prefs_remember_last_upload_location_summary">Salvare l\'ultimo percorso usata per l\'upload</string>
+  <string name="prefs_remember_last_share_location">Salva la posizione</string>
   <string name="recommend_subject">Prova %1$s sul tuo smartphone!</string>
   <string name="recommend_text">Vorrei invitarti a usare %1$s sul tuo smartphone!\nScarica qui: %2$s</string>
   <string name="auth_check_server">Verifica server</string>
index be00674..7328f8e 100644 (file)
@@ -30,6 +30,8 @@
   <string name="prefs_recommend">Rekommendera till en vän</string>
   <string name="prefs_feedback">Feedback</string>
   <string name="prefs_imprint">Imprint</string>
+  <string name="prefs_remember_last_share_location">Kom ihåg uppladdningsplats</string>
+  <string name="prefs_remember_last_upload_location_summary">Kom ihåg senaste uppladdningsplatsen för delning</string>
   <string name="recommend_subject">Försök %1$s på din smarttelefon!</string>
   <string name="recommend_text">Jag skulle vilja bjuda in dig till att använda %1$s på din smartphone!\nLadda ner här: %2$s</string>
   <string name="auth_check_server">Kontrollera Server</string>
index 4c7cf34..30c9557 100644 (file)
@@ -31,7 +31,9 @@
     <string name="prefs_recommend">Recommend to a friend</string>
     <string name="prefs_feedback">Feedback</string>
     <string name="prefs_imprint">Imprint</string>
-    
+    <string name="prefs_remember_last_share_location">Remember share location</string>
+    <string name="prefs_remember_last_upload_location_summary">Remember last share upload location</string>
+
        <string name="recommend_subject">"Try %1$s on your smartphone!"</string>
        <string name="recommend_text">"I want to invite you to use %1$s on your smartphone!\nDownload here: %2$s"</string>
 
        <string name="network_error_socket_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
        <string name="network_error_connect_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
        <string name="network_host_not_available">The operation couldn\'t be completed, server is unavailable</string>
+
        <string name="empty"></string>
        
        <string name="forbidden_permissions">You do not have permission %s</string>
        <string name="move_file_invalid_overwrite">The file exists already in the destination folder</string>
        <string name="move_file_error">An error occurred while trying to move this file or folder</string>
        <string name="forbidden_permissions_move">to move this file</string>
-
 </resources>
index 945e853..77ef6ed 100644 (file)
@@ -32,6 +32,9 @@
     <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading" 
                         android:title="@string/prefs_instant_upload"  
                         android:summary="@string/prefs_instant_upload_summary"/>
+    <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="save_last_upload_location"
+        android:title="@string/prefs_remember_last_share_location"
+        android:summary="@string/prefs_remember_last_upload_location_summary"/>
     <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:dependency="instant_uploading" 
                                        android:disableDependentsState="true" 
                                        android:title="@string/instant_upload_on_wifi" 
index 9ac6e27..01c235c 100644 (file)
@@ -51,6 +51,7 @@ import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.db.DbHandler;
+import com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.LongClickableCheckBoxPreference;
 import com.owncloud.android.utils.DisplayUtils;
@@ -68,6 +69,7 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
 
     private DbHandler mDbHandler;
     private CheckBoxPreference pCode;
+    private CheckBoxPreference pSaveLocation;
     private Preference pAboutApp;
 
     private PreferenceCategory mAccountsPrefCategory = null;
@@ -131,6 +133,24 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
             
         }
 
+        pSaveLocation = (CheckBoxPreferenceWithLongTitle) findPreference("save_last_upload_location");
+        if(pSaveLocation != null){
+            pSaveLocation.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+                @Override
+                public boolean onPreferenceChange(Preference preference, Object newValue) {
+                    //The saved path is removed when the preference is turned off
+                    if( newValue instanceof Boolean  && !(Boolean) newValue) {
+                        SharedPreferences.Editor appPrefs = PreferenceManager
+                                       .getDefaultSharedPreferences(getApplicationContext()).edit();
+                        appPrefs.remove("last_upload_path");
+                        appPrefs.commit();
+                    }
+                    return true;
+                }
+            });
+        }
+
+
         PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("more");
         
         boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
index 62ad44a..d45ed4b 100644 (file)
@@ -39,22 +39,22 @@ import android.accounts.AccountManager;
 import android.app.AlertDialog;
 import android.app.AlertDialog.Builder;
 import android.app.Dialog;
-import android.app.ListActivity;
 import android.app.ProgressDialog;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnCancelListener;
 import android.content.DialogInterface.OnClickListener;
 import android.content.Intent;
+import android.content.SharedPreferences;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Parcelable;
+import android.preference.PreferenceManager;
 import android.provider.MediaStore.Audio;
 import android.provider.MediaStore.Images;
 import android.provider.MediaStore.Video;
 import android.view.View;
-import android.view.Window;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.Button;
@@ -62,6 +62,25 @@ import android.widget.EditText;
 import android.widget.SimpleAdapter;
 import android.widget.Toast;
 
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.app.SherlockListActivity;
+import com.owncloud.android.MainApp;
+import com.owncloud.android.R;
+import com.owncloud.android.authentication.AccountAuthenticator;
+import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.files.services.FileUploader;
+import com.owncloud.android.utils.DisplayUtils;
+import com.owncloud.android.utils.Log_OC;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Stack;
+import java.util.Vector;
+
 
 /**
  * This can be used to upload things to an ownCloud instance.
@@ -69,7 +88,7 @@ import android.widget.Toast;
  * @author Bartek Przybylski
  * 
  */
-public class Uploader extends ListActivity implements OnItemClickListener, android.view.View.OnClickListener {
+public class Uploader extends SherlockListActivity implements OnItemClickListener, android.view.View.OnClickListener {
     private static final String TAG = "ownCloudUploader";
 
     private Account mAccount;
@@ -80,6 +99,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
     private String mUploadPath;
     private FileDataStorageManager mStorageManager;
     private OCFile mFile;
+    private boolean mSaveUploadLocation;
 
     private final static int DIALOG_NO_ACCOUNT = 0;
     private final static int DIALOG_WAITING = 1;
@@ -91,9 +111,11 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
         mParents = new Stack<String>();
-        mParents.add("");
+
+        ActionBar actionBar = getSherlock().getActionBar();
+        actionBar.setIcon(DisplayUtils.getSeasonalIconId());
+
         if (prepareStreamsToUpload()) {
             mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
             Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType());
@@ -104,8 +126,37 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
                 Log_OC.i(TAG, "More then one ownCloud is available");
                 showDialog(DIALOG_MULTIPLE_ACCOUNT);
             } else {
+
                 mAccount = accounts[0];
                 mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());
+
+                SharedPreferences appPreferences = PreferenceManager
+                        .getDefaultSharedPreferences(getApplicationContext());
+
+                mSaveUploadLocation = appPreferences.getBoolean("save_last_upload_location", false);
+
+                //If the users has enabled last upload path saving then populate mParents with the previous path
+                if(mSaveUploadLocation)
+                {
+                    String last_path = appPreferences.getString("last_upload_path", "");
+                    // "/" equals root-directory
+                    if(last_path.equals("/")) {
+                        mParents.add("");
+                    }
+                    else{
+                        String[] dir_names = last_path.split("/");
+                        for (String dir : dir_names)
+                            mParents.add(dir);
+                    }
+                    //Make sure that path still exists, if it doesn't pop the stack and try the previous path
+                    while(!mStorageManager.fileExists(generatePath(mParents))){
+                        mParents.pop();
+                    }
+                }
+                else {
+                    mParents.add("");
+                }
+
                 populateDirectoryList();
             }
         } else {
@@ -288,12 +339,18 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
     private void populateDirectoryList() {
         setContentView(R.layout.uploader_layout);
 
-        String full_path = "";
-        for (String a : mParents)
-            full_path += a + "/";
+        String current_dir = mParents.peek();
+        if(current_dir.equals("")){
+            getActionBar().setTitle(getString(R.string.default_display_name_for_root_folder));
+        }
+        else{
+            getActionBar().setTitle(current_dir);
+        }
+
+        String full_path = generatePath(mParents);
         
         Log_OC.d(TAG, "Populating view with content of : " + full_path);
-        
+
         mFile = mStorageManager.getFileByPath(full_path);
         if (mFile != null) {
             Vector<OCFile> files = mStorageManager.getFolderContent(mFile);
@@ -317,6 +374,14 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
         }
     }
 
+    private String generatePath(Stack<String> dirs) {
+        String full_path = "";
+
+        for (String a : dirs)
+            full_path += a + "/";
+        return full_path;
+    }
+
     private boolean prepareStreamsToUpload() {
         if (getIntent().getAction().equals(Intent.ACTION_SEND)) {
             mStreamsToUpload = new ArrayList<Parcelable>();
@@ -408,6 +473,15 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
             intent.putExtra(FileUploader.KEY_REMOTE_FILE, remote.toArray(new String[remote.size()]));
             intent.putExtra(FileUploader.KEY_ACCOUNT, mAccount);
             startService(intent);
+
+            //If the user has enabled last upload path then save the path to shared preferences
+            if(mSaveUploadLocation){
+                SharedPreferences.Editor appPrefs = PreferenceManager
+                        .getDefaultSharedPreferences(getApplicationContext()).edit();
+                appPrefs.putString("last_upload_path", mUploadPath);
+                appPrefs.apply();
+            }
+
             finish();
             }