Merge lp:~j-4-deactivatedaccount/tomdroid/folder-location into lp:~tomdroid-maintainers/tomdroid/main

Proposed by Stefan Hammer
Status: Merged
Merged at revision: 281
Proposed branch: lp:~j-4-deactivatedaccount/tomdroid/folder-location
Merge into: lp:~tomdroid-maintainers/tomdroid/main
Diff against target: 307 lines (+89/-30)
10 files modified
project.properties (+0/-17)
res/values/strings.xml (+3/-0)
res/xml/preferences.xml (+5/-0)
src/org/tomdroid/sync/SyncService.java (+1/-0)
src/org/tomdroid/sync/sd/SdCardSyncService.java (+5/-0)
src/org/tomdroid/sync/web/SnowySyncService.java (+4/-0)
src/org/tomdroid/ui/PreferencesActivity.java (+64/-0)
src/org/tomdroid/ui/ShortcutActivity.java (+0/-1)
src/org/tomdroid/ui/Tomdroid.java (+6/-12)
src/org/tomdroid/util/Preferences.java (+1/-0)
To merge this branch: bzr merge lp:~j-4-deactivatedaccount/tomdroid/folder-location
Reviewer Review Type Date Requested Status
Olivier Bilodeau Approve
Review via email: mp+80733@code.launchpad.net
To post a comment you must log in.
258. By Stefan Hammer

Disable Logging, remove changes in whitspace.

Revision history for this message
Stefan Hammer (j-4-deactivatedaccount) wrote :

Hi! I am quite sure, the code doesn't mess up something.
Still, can somebody build it and check for some unusual cases?
There should not be a problem with slashes before and after the folder name, one can also choose a subfolder. If the field is empty, it should load the notes from the root of the sd-card.
If there are no notes in the selected folder, a error message says: No notes found on SD card.

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

Hi Stefan,

EditTextPreference is used for setting folder location now. I think it is troublesome.
If we can pick a location using a list, it's perfect!

How is your opinion?

Revision history for this message
Stefan Hammer (j-4-deactivatedaccount) wrote :

I also thought of giving the chance to write anything is probably not the best solution.
But if you write nonsense, the worst case scenario is Tomdroid telling you that it could not find any notes there.
So - nothing is ruined :-)

Your idea is to provide a list with all existing folders paths on the sdcard root?
This will be a long list.
Or we just list the folders without sub-directories... But some people wish this feature for synchronisation with Dropbox and I think they will need sub-directories then.
What is your exact idea?

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

In my opinion, the list shows folders without sub-directories, and when we tapped a folder, then the list changes the current directory to tapped one. It's like a folder browser. And we put "Choose" and "Cancel" buttons to choose the folder.

I took a screenshot of the draft:
http://ubuntuone.com/4upyKmPn5BdXFKW3AJpFsZ

It's just a draft and it doesn't work.

Revision history for this message
Stefan Hammer (j-4-deactivatedaccount) wrote :

Mhmm. I am not really satisfied with setting up a whole filebrowser just for picking a foldername for the storage of the notes. Most of the Android applications do not offer to choose the folder name at all and just save where ever they think. I am also sure, this habit is kind of a android design thing, where folders and files don't play a role any more, because they make everything more complicated.

Our Location Setting would just be for power-users, who want to use Dropbox or need to customise everything.

I now thought of a simple ListPreference with Radiobuttons just showing the folders/paths where *.note files are saved. So we scrobble the sdcard for *.note files and present the positive folder-paths. If there are no notes stored on the sdcard, we show a hint telling to save the notes in one folder first, default would be /tomdroid.

I think this is probably the user-friendliest way, also considering the way a new user has to learn the approach. He will pick the SD-Card setting and then the location button is enabled -> clicking on there searches for notes. If there are already notes present, good - if not, we tell him, what to do next!

Do you think, this is good and can be done?

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

I thought your idea is best.
RadioButton is useful and auto scanning function is great.

However it also have a problem.
We will add note taking feature. So I think some users will want to choose blank directory.

How do you think about it?

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

Hi,

I created an experimental sub-branch that contains folder-browser to choose a location on SD card.
lp:~vbkaisetsu/tomdroid/folder-location-browser

Could you test it?

259. By Stefan Hammer

merged lp:tomdroid

260. By Stefan Hammer

Change PreferenceSummary to display folder path

261. By Stefan Hammer

merge lp:tomdroid

262. By Stefan Hammer

default.properties got renamed to project.properties

263. By Stefan Hammer

merged lp:tomdroid and made little improvements for error reporting.

264. By Stefan Hammer

merged with lp:tomdroid again

265. By Stefan Hammer

changed strings...

266. By Stefan Hammer

chaged error handling

267. By Stefan Hammer

merge lp:tomdroid

268. By Stefan Hammer

remove whitespace and unused imports.

Revision history for this message
Olivier Bilodeau (plaxx) wrote :

Fine like that.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'project.properties'
2--- project.properties 1970-01-01 00:00:00 +0000
3+++ project.properties 2012-03-31 20:36:20 +0000
4@@ -0,0 +1,17 @@
5+# This file is automatically generated by Android Tools.
6+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
7+#
8+# This file must be checked in Version Control Systems.
9+#
10+# To customize properties used by the Ant build system edit
11+# "ant.properties", and override values to adapt the script to your
12+# project structure.
13+#
14+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
15+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
16+
17+# Indicates whether an apk should be generated for each density.
18+split.density=false
19+# Project target.
20+target=android-4
21+apk-configurations=
22
23=== removed file 'project.properties'
24--- project.properties 2012-03-31 18:40:05 +0000
25+++ project.properties 1970-01-01 00:00:00 +0000
26@@ -1,17 +0,0 @@
27-# This file is automatically generated by Android Tools.
28-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
29-#
30-# This file must be checked in Version Control Systems.
31-#
32-# To customize properties used by the Ant build system edit
33-# "ant.properties", and override values to adapt the script to your
34-# project structure.
35-#
36-# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
37-#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
38-
39-# Indicates whether an apk should be generated for each density.
40-split.density=false
41-# Project target.
42-target=android-4
43-apk-configurations=
44
45=== modified file 'res/values/strings.xml'
46--- res/values/strings.xml 2012-03-31 20:27:03 +0000
47+++ res/values/strings.xml 2012-03-31 20:36:20 +0000
48@@ -55,6 +55,9 @@
49 <string name="prefSDCard">SD Card</string>
50 <string name="prefTomboyWeb">Online Synchronization</string>
51 <string name="prefAuthenticate">Authenticate</string>
52+ <string name="prefLocation">Location on SD Card</string>
53+ <string name="prefFolderCreated">The folder \"%1$s\" does not exist yet. Please connect your device to the computer, create the folder and fill it with *.note files.</string>
54+ <string name="prefNoValidLocation">\"%1$s\" is no valid folder location. Please try again!</string>
55
56 <string name="prefSyncCompleteAuth">Completing authentication. Please wait...</string>
57 <string name="prefSyncConnectionFailed">The connection to the server has failed, please check that the address you entered is correct.</string>
58
59=== modified file 'res/xml/preferences.xml'
60--- res/xml/preferences.xml 2011-09-05 21:44:12 +0000
61+++ res/xml/preferences.xml 2012-03-31 20:36:20 +0000
62@@ -34,6 +34,11 @@
63 android:title="@string/prefSyncServer"
64 android:positiveButtonText="@string/prefAuthenticate"
65 android:shouldDisableView="true"/>
66+
67+ <EditTextPreference android:key="sd_location"
68+ android:title="@string/prefLocation"
69+ android:positiveButtonText="@string/btnOk"
70+ android:shouldDisableView="true"/>
71 </PreferenceCategory>
72 <PreferenceCategory android:title="@string/prefSearch">
73 <Preference
74
75=== modified file 'src/org/tomdroid/sync/SyncService.java'
76--- src/org/tomdroid/sync/SyncService.java 2012-03-31 14:36:55 +0000
77+++ src/org/tomdroid/sync/SyncService.java 2012-03-31 20:36:20 +0000
78@@ -85,6 +85,7 @@
79
80 protected abstract void sync();
81 public abstract boolean needsServer();
82+ public abstract boolean needsLocation();
83 public abstract boolean needsAuth();
84
85 /**
86
87=== modified file 'src/org/tomdroid/sync/sd/SdCardSyncService.java'
88--- src/org/tomdroid/sync/sd/SdCardSyncService.java 2012-03-31 14:36:55 +0000
89+++ src/org/tomdroid/sync/sd/SdCardSyncService.java 2012-03-31 20:36:20 +0000
90@@ -72,6 +72,11 @@
91 }
92
93 @Override
94+ public boolean needsLocation() {
95+ return true;
96+ }
97+
98+ @Override
99 public boolean needsAuth() {
100 return false;
101 }
102
103=== modified file 'src/org/tomdroid/sync/web/SnowySyncService.java'
104--- src/org/tomdroid/sync/web/SnowySyncService.java 2012-03-31 14:36:55 +0000
105+++ src/org/tomdroid/sync/web/SnowySyncService.java 2012-03-31 20:36:20 +0000
106@@ -69,6 +69,10 @@
107 }
108
109 @Override
110+ public boolean needsLocation() {
111+ return false;
112+ }
113+ @Override
114 public boolean needsAuth() {
115 return true;
116 }
117
118=== modified file 'src/org/tomdroid/ui/PreferencesActivity.java'
119--- src/org/tomdroid/ui/PreferencesActivity.java 2011-10-27 16:33:12 +0000
120+++ src/org/tomdroid/ui/PreferencesActivity.java 2012-03-31 20:36:20 +0000
121@@ -30,6 +30,7 @@
122 import android.content.Intent;
123 import android.net.Uri;
124 import android.os.Bundle;
125+import android.os.Environment;
126 import android.os.Handler;
127 import android.os.Message;
128 import android.preference.EditTextPreference;
129@@ -50,6 +51,7 @@
130 import org.tomdroid.util.SearchSuggestionProvider;
131 import org.tomdroid.util.TLog;
132
133+import java.io.File;
134 import java.util.ArrayList;
135
136 public class PreferencesActivity extends PreferenceActivity {
137@@ -59,6 +61,7 @@
138 // TODO: put the various preferences in fields and figure out what to do on activity suspend/resume
139 private EditTextPreference syncServer = null;
140 private ListPreference syncService = null;
141+ private EditTextPreference sdLocation = null;
142 private Preference clearSearchHistory = null;
143
144 @Override
145@@ -70,6 +73,7 @@
146 // Fill the Preferences fields
147 syncServer = (EditTextPreference)findPreference(Preferences.Key.SYNC_SERVER.getName());
148 syncService = (ListPreference)findPreference(Preferences.Key.SYNC_SERVICE.getName());
149+ sdLocation = (EditTextPreference)findPreference(Preferences.Key.SD_LOCATION.getName());
150 clearSearchHistory = (Preference)findPreference(Preferences.Key.CLEAR_SEARCH_HISTORY.getName());
151
152 // Set the default values if nothing exists
153@@ -115,6 +119,39 @@
154
155 });
156
157+ // Change the Folder Location
158+ sdLocation.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
159+
160+ public boolean onPreferenceChange(Preference preference, Object locationUri) {
161+
162+ if (locationUri.equals(Preferences.getString(Preferences.Key.SD_LOCATION))) {
163+ return false;
164+ }
165+ if (locationUri.toString().contains("\n")) {
166+ noValidLocation(locationUri.toString());
167+ return false;
168+ }
169+
170+ File path = new File(Environment.getExternalStorageDirectory()
171+ + "/" + locationUri + "/");
172+
173+ if(!path.exists()) {
174+ TLog.d(TAG, "Folder {0} does not exist.", path);
175+ folderNotExisting(path.toString());
176+ return false;
177+ }
178+
179+ Preferences.putString(Preferences.Key.SD_LOCATION, locationUri.toString());
180+ TLog.d(TAG, "Changed Folder to: " + path.toString());
181+
182+ Tomdroid.NOTES_PATH = path.toString();
183+ sdLocation.setSummary(Tomdroid.NOTES_PATH);
184+
185+ resetLocalDatabase();
186+ return true;
187+ }
188+ });
189+
190 //delete Search History
191 clearSearchHistory.setOnPreferenceClickListener(new OnPreferenceClickListener() {
192 public boolean onPreferenceClick(Preference preference) {
193@@ -207,6 +244,11 @@
194 syncService.setDefaultValue(defaultService);
195 if(syncService.getValue() == null)
196 syncService.setValue(defaultService);
197+
198+ String defaultLocation = (String)Preferences.Key.SD_LOCATION.getDefault();
199+ sdLocation.setDefaultValue(defaultLocation);
200+ if(sdLocation.getText() == null)
201+ sdLocation.setText(defaultLocation);
202
203 }
204
205@@ -219,6 +261,8 @@
206
207 syncServer.setEnabled(service.needsServer());
208 syncService.setSummary(service.getDescription());
209+ sdLocation.setEnabled(service.needsLocation());
210+ sdLocation.setSummary(Tomdroid.NOTES_PATH);
211 }
212
213 private void connectionFailed() {
214@@ -230,6 +274,26 @@
215 }})
216 .show();
217 }
218+
219+ private void folderNotExisting(String path) {
220+ new AlertDialog.Builder(this)
221+ .setMessage(String.format(getString(R.string.prefFolderCreated), path))
222+ .setNeutralButton(getString(R.string.btnOk), new OnClickListener() {
223+ public void onClick(DialogInterface dialog, int which) {
224+ dialog.dismiss();
225+ }})
226+ .show();
227+ }
228+
229+ private void noValidLocation(String path) {
230+ new AlertDialog.Builder(this)
231+ .setMessage(String.format(getString(R.string.prefNoValidLocation), path))
232+ .setNeutralButton(getString(R.string.btnOk), new OnClickListener() {
233+ public void onClick(DialogInterface dialog, int which) {
234+ dialog.dismiss();
235+ }})
236+ .show();
237+ }
238
239 //TODO use LocalStorage wrapper from two-way-sync branch when it get's merged
240 private void resetLocalDatabase() {
241
242=== modified file 'src/org/tomdroid/ui/ShortcutActivity.java'
243--- src/org/tomdroid/ui/ShortcutActivity.java 2012-03-31 19:21:16 +0000
244+++ src/org/tomdroid/ui/ShortcutActivity.java 2012-03-31 20:36:20 +0000
245@@ -25,7 +25,6 @@
246 import android.app.ListActivity;
247 import android.database.Cursor;
248 import android.os.Bundle;
249-import android.util.Log;
250 import android.view.View;
251 import android.widget.ListAdapter;
252 import android.widget.ListView;
253
254=== modified file 'src/org/tomdroid/ui/Tomdroid.java'
255--- src/org/tomdroid/ui/Tomdroid.java 2012-03-31 19:16:05 +0000
256+++ src/org/tomdroid/ui/Tomdroid.java 2012-03-31 20:36:20 +0000
257@@ -55,15 +55,6 @@
258 import android.widget.ListAdapter;
259 import android.widget.ListView;
260 import android.widget.TextView;
261-import org.tomdroid.Note;
262-import org.tomdroid.NoteManager;
263-import org.tomdroid.R;
264-import org.tomdroid.sync.ServiceAuth;
265-import org.tomdroid.sync.SyncManager;
266-import org.tomdroid.sync.SyncService;
267-import org.tomdroid.util.FirstNote;
268-import org.tomdroid.util.Preferences;
269-import org.tomdroid.util.Send;
270 import org.tomdroid.util.TLog;
271
272 public class Tomdroid extends ListActivity {
273@@ -78,9 +69,8 @@
274 public static final String PROJECT_HOMEPAGE = "http://www.launchpad.net/tomdroid/";
275
276 // config parameters
277- // TODO hardcoded for now
278- public static final String NOTES_PATH = Environment.getExternalStorageDirectory()
279- + "/tomdroid/";
280+ public static String NOTES_PATH = null;
281+
282 // Set this to false for release builds, the reason should be obvious
283 public static final boolean CLEAR_PREFERENCES = false;
284
285@@ -106,6 +96,10 @@
286 setContentView(R.layout.main);
287 Preferences.init(this, CLEAR_PREFERENCES);
288
289+ // get the Path to the notes-folder from Preferences
290+ NOTES_PATH = Environment.getExternalStorageDirectory()
291+ + "/" + Preferences.getString(Preferences.Key.SD_LOCATION) + "/";
292+
293 // did we already show the warning and got destroyed by android's activity killer?
294 if (Preferences.getBoolean(Preferences.Key.FIRST_RUN)) {
295 TLog.i(TAG, "Tomdroid is first run.");
296
297=== modified file 'src/org/tomdroid/util/Preferences.java'
298--- src/org/tomdroid/util/Preferences.java 2011-09-04 17:48:08 +0000
299+++ src/org/tomdroid/util/Preferences.java 2012-03-31 20:36:20 +0000
300@@ -34,6 +34,7 @@
301 SYNC_SERVER_ROOT_API ("sync_server_root_api", ""),
302 SYNC_SERVER_USER_API ("sync_server_user_api", ""),
303 SYNC_SERVER ("sync_server", "https://one.ubuntu.com/notes"),
304+ SD_LOCATION ("sd_location", "tomdroid"),
305 CLEAR_SEARCH_HISTORY ("clearSearchHistory", ""),
306 ACCESS_TOKEN ("access_token", ""),
307 ACCESS_TOKEN_SECRET ("access_token_secret", ""),

Subscribers

People subscribed via source and target branches