소스 검색

Added persistence of file extension selection per type

AndyScherzinger 8 년 전
부모
커밋
96229c6c6b
2개의 변경된 파일76개의 추가작업 그리고 10개의 파일을 삭제
  1. 46 0
      src/com/owncloud/android/db/PreferenceManager.java
  2. 30 10
      src/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java

+ 46 - 0
src/com/owncloud/android/db/PreferenceManager.java

@@ -35,6 +35,8 @@ public abstract class PreferenceManager {
     private static final String AUTO_PREF__LAST_UPLOAD_PATH = "last_upload_path";
     private static final String AUTO_PREF__SORT_ORDER = "sort_order";
     private static final String AUTO_PREF__SORT_ASCENDING = "sort_ascending";
+    private static final String AUTO_PREF__UPLOAD_FILE_EXTENSION_MAP_URL = "prefs_upload_file_extension_map_url";
+    private static final String AUTO_PREF__UPLOAD_FILE_EXTENSION_URL = "prefs_upload_file_extension_url";
     private static final String AUTO_PREF__UPLOADER_BEHAVIOR = "prefs_uploader_behaviour";
     private static final String PREF__INSTANT_UPLOADING = "instant_uploading";
     private static final String PREF__INSTANT_VIDEO_UPLOADING = "instant_video_uploading";
@@ -77,6 +79,50 @@ public abstract class PreferenceManager {
         return PreferenceManager.getDefaultSharedPreferences(context).getBoolean("show_hidden_files_pref", false);
     }
 
+    /**
+     * Gets the selected file extension position the user selected to do the last upload of a url file shared from other
+     * app.
+     *
+     * @param context Caller {@link Context}, used to access to shared preferences manager.
+     * @return selectedPos     the selected file extension position.
+     */
+    public static int getUploadUrlFileExtensionUrlSelectedPos(Context context) {
+        return getDefaultSharedPreferences(context).getInt(AUTO_PREF__UPLOAD_FILE_EXTENSION_URL, 0);
+    }
+
+    /**
+     * Saves the selected file extension position the user selected to do the last upload of a url file shared from
+     * other app.
+     *
+     * @param context     Caller {@link Context}, used to access to shared preferences manager.
+     * @param selectedPos the selected file extension position.
+     */
+    public static void setUploadUrlFileExtensionUrlSelectedPos(Context context, int selectedPos) {
+        saveIntPreference(context, AUTO_PREF__UPLOAD_FILE_EXTENSION_URL, selectedPos);
+    }
+
+    /**
+     * Gets the selected map file extension position the user selected to do the last upload of a url file shared
+     * from other app.
+     *
+     * @param context Caller {@link Context}, used to access to shared preferences manager.
+     * @return selectedPos     the selected file extension position.
+     */
+    public static int getUploadMapFileExtensionUrlSelectedPos(Context context) {
+        return getDefaultSharedPreferences(context).getInt(AUTO_PREF__UPLOAD_FILE_EXTENSION_MAP_URL, 0);
+    }
+
+    /**
+     * Saves the selected map file extension position the user selected to do the last upload of a url file shared from
+     * other app.
+     *
+     * @param context     Caller {@link Context}, used to access to shared preferences manager.
+     * @param selectedPos the selected file extension position.
+     */
+    public static void setUploadMapFileExtensionUrlSelectedPos(Context context, int selectedPos) {
+        saveIntPreference(context, AUTO_PREF__UPLOAD_FILE_EXTENSION_MAP_URL, selectedPos);
+    }
+
     /**
      * Gets the path where the user selected to do the last upload of a file shared from other app.
      *

+ 30 - 10
src/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java

@@ -316,18 +316,20 @@ public class ReceiveExternalFilesActivity extends FileActivity
     }
 
     public static class DialogInputUploadFilename extends DialogFragment {
-        private final static String KEY_SUBJECT_TEXT = "SUBJECT_TEXT";
-        private final static String KEY_EXTRA_TEXT = "EXTRA_TEXT";
+        private static final String KEY_SUBJECT_TEXT = "SUBJECT_TEXT";
+        private static final String KEY_EXTRA_TEXT = "EXTRA_TEXT";
+
+        private static final int CATEGORY_URL = 1;
+        private static final int CATEGORY_MAPS_URL = 2;
 
         private List<String> mFilenameBase;
         private List<String> mFilenameSuffix;
         private List<String> mText;
+        private int mFileCategory;
 
         private Spinner mSpinner;
 
-        public static DialogInputUploadFilename newInstance(
-            String subjectText, String extraText
-        ) {
+        public static DialogInputUploadFilename newInstance(String subjectText, String extraText) {
             DialogInputUploadFilename dialog = new DialogInputUploadFilename();
             Bundle args = new Bundle();
             args.putString(KEY_SUBJECT_TEXT, subjectText);
@@ -368,7 +370,6 @@ public class ReceiveExternalFilesActivity extends FileActivity
                 mFilenameBase.add(filename);
                 mFilenameSuffix.add(URL_FILE_SUFFIX);
                 adapter.add(String.format(str,URL_FILE_SUFFIX));
-                selectPos = adapter.getCount()-1;
 
                 mText.add(internetShortcutWeblocText(extraText));
                 mFilenameBase.add(filename);
@@ -379,15 +380,16 @@ public class ReceiveExternalFilesActivity extends FileActivity
                 mFilenameBase.add(filename);
                 mFilenameSuffix.add(DESKTOP_FILE_SUFFIX);
                 adapter.add(String.format(str,DESKTOP_FILE_SUFFIX));
-            }
-            if (isIntentFromGoogleMap(subjectText, extraText)) {
+
+                selectPos = PreferenceManager.getUploadUrlFileExtensionUrlSelectedPos(getActivity());
+                mFileCategory = CATEGORY_URL;
+            } else if (isIntentFromGoogleMap(subjectText, extraText)) {
                 String str = getString(R.string.upload_file_dialog_filetype_googlemap_shortcut);
                 String texts[] = extraText.split("\n");
                 mText.add(internetShortcutUrlText(texts[2]));
                 mFilenameBase.add(texts[0]);
                 mFilenameSuffix.add(URL_FILE_SUFFIX);
                 adapter.add(String.format(str,URL_FILE_SUFFIX));
-                selectPos = adapter.getCount()-1;
 
                 mText.add(internetShortcutWeblocText(texts[2]));
                 mFilenameBase.add(texts[0]);
@@ -398,6 +400,9 @@ public class ReceiveExternalFilesActivity extends FileActivity
                 mFilenameBase.add(texts[0]);
                 mFilenameSuffix.add(DESKTOP_FILE_SUFFIX);
                 adapter.add(String.format(str,DESKTOP_FILE_SUFFIX));
+
+                selectPos = PreferenceManager.getUploadMapFileExtensionUrlSelectedPos(getActivity());
+                mFileCategory = CATEGORY_MAPS_URL;
             }
 
             final EditText userInput = (EditText) view.findViewById(R.id.user_input);
@@ -427,6 +432,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
                     Spinner spinner = (Spinner) parent;
                     int selectPos = spinner.getSelectedItemPosition();
                     setFilename(userInput, selectPos);
+                    saveSelection(selectPos);
                 }
 
                 @Override
@@ -454,7 +460,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
 
                     File file = createTempFile("tmp.tmp", mText.get(selectPos));
                     if (file == null) {
-                        ((ReceiveExternalFilesActivity)getActivity()).finish();
+                        getActivity().finish();
                     }
                     String tmpname = file.getAbsolutePath();
 
@@ -475,6 +481,20 @@ public class ReceiveExternalFilesActivity extends FileActivity
             super.onPause();
         }
 
+        private void saveSelection(int selectPos) {
+            switch (mFileCategory) {
+                case CATEGORY_URL:
+                    PreferenceManager.setUploadUrlFileExtensionUrlSelectedPos(getActivity(), selectPos);
+                    break;
+                case CATEGORY_MAPS_URL:
+                    PreferenceManager.setUploadMapFileExtensionUrlSelectedPos(getActivity(), selectPos);
+                    break;
+                default:
+                    Log_OC.d(TAG, "Simple text snippet only: no selection to be persisted");
+                    break;
+            }
+        }
+
         private void hideSpinnerDropDown(Spinner spinner) {
             try {
                 Method method = Spinner.class.getDeclaredMethod("onDetachedFromWindow");