Browse code
Works
fiddlerwoaroof authored on 17/04/2015 23:50:20
Showing 19 changed files
Showing 19 changed files
- app/app.iml
- app/build.gradle
- app/src/main/AndroidManifest.xml
- app/src/main/java/com/joinmarrow/marrow/MarrowActivity.java
- app/src/main/java/com/joinmarrow/marrow/tasks/AddLink.java
- app/src/main/java/com/joinmarrow/marrow/tasks/GetBoneTask.java
- app/src/main/java/com/joinmarrow/marrow/tasks/GetSubscriptions.java
- app/src/main/java/com/joinmarrow/marrow/tasks/LogonTask.java
- app/src/main/res/drawable-hdpi/ic_action_new.png
- app/src/main/res/drawable-hdpi/ic_action_search.png
- app/src/main/res/drawable-mdpi/ic_action_new.png
- app/src/main/res/drawable-mdpi/ic_action_search.png
- app/src/main/res/drawable-xhdpi/ic_action_new.png
- app/src/main/res/drawable-xhdpi/ic_action_search.png
- app/src/main/res/drawable-xxhdpi/ic_action_new.png
- app/src/main/res/drawable-xxhdpi/ic_action_search.png
- app/src/main/res/menu/menu_marrow.xml
- app/src/main/res/values/strings.xml
- app/src/main/res/values/styles.xml
... | ... |
@@ -83,35 +83,38 @@ |
83 | 83 |
<excludeFolder url="file://$MODULE_DIR$/build/outputs" /> |
84 | 84 |
<excludeFolder url="file://$MODULE_DIR$/build/tmp" /> |
85 | 85 |
</content> |
86 |
- <orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" /> |
|
86 |
+ <orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" /> |
|
87 | 87 |
<orderEntry type="sourceFolder" forTests="false" /> |
88 |
- <orderEntry type="library" exported="" name="play-services-drive-7.0.0" level="project" /> |
|
89 |
- <orderEntry type="library" exported="" name="play-services-maps-7.0.0" level="project" /> |
|
90 |
- <orderEntry type="library" exported="" name="play-services-appindexing-7.0.0" level="project" /> |
|
91 |
- <orderEntry type="library" exported="" name="play-services-cast-7.0.0" level="project" /> |
|
92 |
- <orderEntry type="library" exported="" name="play-services-wearable-7.0.0" level="project" /> |
|
93 |
- <orderEntry type="library" exported="" name="play-services-panorama-7.0.0" level="project" /> |
|
94 |
- <orderEntry type="library" exported="" name="jdeferred-core-1.2.3" level="project" /> |
|
95 |
- <orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" /> |
|
96 | 88 |
<orderEntry type="library" exported="" name="play-services-plus-7.0.0" level="project" /> |
97 |
- <orderEntry type="library" exported="" name="play-services-7.0.0" level="project" /> |
|
98 |
- <orderEntry type="library" exported="" name="play-services-ads-7.0.0" level="project" /> |
|
89 |
+ <orderEntry type="library" exported="" name="javacc-4.1" level="project" /> |
|
99 | 90 |
<orderEntry type="library" exported="" name="play-services-base-7.0.0" level="project" /> |
91 |
+ <orderEntry type="library" exported="" name="play-services-panorama-7.0.0" level="project" /> |
|
92 |
+ <orderEntry type="library" exported="" name="play-services-safetynet-7.0.0" level="project" /> |
|
100 | 93 |
<orderEntry type="library" exported="" name="play-services-location-7.0.0" level="project" /> |
101 |
- <orderEntry type="library" exported="" name="slf4j-api-1.7.2" level="project" /> |
|
94 |
+ <orderEntry type="library" exported="" name="cardview-v7-21.0.3" level="project" /> |
|
95 |
+ <orderEntry type="library" exported="" name="play-services-appindexing-7.0.0" level="project" /> |
|
96 |
+ <orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" /> |
|
97 |
+ <orderEntry type="library" exported="" name="play-services-7.0.0" level="project" /> |
|
98 |
+ <orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" /> |
|
99 |
+ <orderEntry type="library" exported="" name="jdeferred-core-1.2.3" level="project" /> |
|
102 | 100 |
<orderEntry type="library" exported="" name="play-services-gcm-7.0.0" level="project" /> |
103 |
- <orderEntry type="library" exported="" name="play-services-safetynet-7.0.0" level="project" /> |
|
104 |
- <orderEntry type="library" exported="" name="play-services-nearby-7.0.0" level="project" /> |
|
105 |
- <orderEntry type="library" exported="" name="play-services-fitness-7.0.0" level="project" /> |
|
101 |
+ <orderEntry type="library" exported="" name="play-services-wearable-7.0.0" level="project" /> |
|
102 |
+ <orderEntry type="library" exported="" name="play-services-wallet-7.0.0" level="project" /> |
|
103 |
+ <orderEntry type="library" exported="" name="play-services-cast-7.0.0" level="project" /> |
|
106 | 104 |
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" /> |
107 |
- <orderEntry type="library" exported="" name="jdeferred-android-aar-1.2.3" level="project" /> |
|
108 |
- <orderEntry type="library" exported="" name="play-services-analytics-7.0.0" level="project" /> |
|
109 |
- <orderEntry type="library" exported="" name="javacc-4.1" level="project" /> |
|
110 |
- <orderEntry type="library" exported="" name="play-services-appstate-7.0.0" level="project" /> |
|
111 |
- <orderEntry type="library" exported="" name="resty-0.3.2" level="project" /> |
|
105 |
+ <orderEntry type="library" exported="" name="play-services-maps-7.0.0" level="project" /> |
|
106 |
+ <orderEntry type="library" exported="" name="play-services-fitness-7.0.0" level="project" /> |
|
112 | 107 |
<orderEntry type="library" exported="" name="play-services-identity-7.0.0" level="project" /> |
108 |
+ <orderEntry type="library" exported="" name="play-services-ads-7.0.0" level="project" /> |
|
109 |
+ <orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" /> |
|
110 |
+ <orderEntry type="library" exported="" name="play-services-appstate-7.0.0" level="project" /> |
|
111 |
+ <orderEntry type="library" exported="" name="play-services-drive-7.0.0" level="project" /> |
|
112 |
+ <orderEntry type="library" exported="" name="play-services-analytics-7.0.0" level="project" /> |
|
113 | 113 |
<orderEntry type="library" exported="" name="play-services-games-7.0.0" level="project" /> |
114 |
- <orderEntry type="library" exported="" name="play-services-wallet-7.0.0" level="project" /> |
|
114 |
+ <orderEntry type="library" exported="" name="jdeferred-android-aar-1.2.3" level="project" /> |
|
115 |
+ <orderEntry type="library" exported="" name="resty-0.3.2" level="project" /> |
|
116 |
+ <orderEntry type="library" exported="" name="slf4j-api-1.7.2" level="project" /> |
|
117 |
+ <orderEntry type="library" exported="" name="play-services-nearby-7.0.0" level="project" /> |
|
115 | 118 |
</component> |
116 | 119 |
</module> |
117 | 120 |
|
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
apply plugin: 'com.android.application' |
2 | 2 |
|
3 | 3 |
android { |
4 |
- compileSdkVersion 19 |
|
4 |
+ compileSdkVersion 22 |
|
5 | 5 |
buildToolsVersion "22.0.1" |
6 | 6 |
|
7 | 7 |
defaultConfig { |
... | ... |
@@ -10,7 +10,7 @@ android { |
10 | 10 |
targetSdkVersion 19 |
11 | 11 |
versionCode 4 |
12 | 12 |
//converges on pi/3 |
13 |
- versionName "1.047" |
|
13 |
+ versionName "1.0471" |
|
14 | 14 |
} |
15 | 15 |
buildTypes { |
16 | 16 |
release { |
... | ... |
@@ -29,5 +29,8 @@ dependencies { |
29 | 29 |
compile 'us.monoid.web:resty:0.3.2' |
30 | 30 |
compile 'org.jdeferred:jdeferred-android-aar:1.2.3' |
31 | 31 |
compile 'com.google.android.gms:play-services:7.0.0' |
32 |
- compile 'com.android.support:support-v4:19.0.0' |
|
32 |
+ compile 'com.android.support:support-v4:22.0.0' |
|
33 |
+ compile 'com.android.support:appcompat-v7:21.0.+' |
|
34 |
+ compile 'com.android.support:cardview-v7:21.0.+' |
|
35 |
+ compile 'com.android.support:recyclerview-v7:21.0.+' |
|
33 | 36 |
} |
... | ... |
@@ -21,6 +21,13 @@ |
21 | 21 |
|
22 | 22 |
<category android:name="android.intent.category.LAUNCHER" /> |
23 | 23 |
</intent-filter> |
24 |
+ |
|
25 |
+ <intent-filter> |
|
26 |
+ <action android:name="android.intent.action.SEND"></action> |
|
27 |
+ <category android:name="android.intent.category.DEFAULT"></category> |
|
28 |
+ <category android:name="android.intent.category.BROWSABLE"></category> |
|
29 |
+ <data android:mimeType="text/plain" /> |
|
30 |
+ </intent-filter> |
|
24 | 31 |
</activity> |
25 | 32 |
<activity android:name=".SettingsActivity" /> |
26 | 33 |
<activity |
... | ... |
@@ -1,13 +1,12 @@ |
1 | 1 |
package com.joinmarrow.marrow; |
2 | 2 |
|
3 |
-import android.app.Activity; |
|
4 | 3 |
import android.content.Context; |
5 | 4 |
import android.content.Intent; |
6 | 5 |
import android.content.SharedPreferences; |
7 | 6 |
import android.net.Uri; |
8 |
-import android.os.AsyncTask; |
|
9 | 7 |
import android.os.Bundle; |
10 | 8 |
import android.preference.PreferenceManager; |
9 |
+import android.support.v7.app.ActionBarActivity; |
|
11 | 10 |
import android.util.Log; |
12 | 11 |
import android.view.KeyEvent; |
13 | 12 |
import android.view.Menu; |
... | ... |
@@ -19,30 +18,26 @@ import android.widget.ArrayAdapter; |
19 | 18 |
import android.widget.ListView; |
20 | 19 |
import android.widget.TextView; |
21 | 20 |
|
21 |
+import com.joinmarrow.marrow.tasks.AddLink; |
|
22 |
+import com.joinmarrow.marrow.tasks.GetBoneTask; |
|
23 |
+import com.joinmarrow.marrow.tasks.GetSubscriptions; |
|
22 | 24 |
import com.joinmarrow.marrow.tasks.LogonTask; |
23 | 25 |
|
24 | 26 |
import org.jdeferred.Deferred; |
25 | 27 |
import org.jdeferred.DoneCallback; |
26 | 28 |
import org.jdeferred.FailCallback; |
27 |
-import org.jdeferred.Promise; |
|
28 | 29 |
import org.jdeferred.impl.DeferredObject; |
29 | 30 |
|
30 |
-import java.io.IOException; |
|
31 | 31 |
import java.util.ArrayList; |
32 |
-import java.util.HashMap; |
|
33 | 32 |
import java.util.List; |
34 | 33 |
|
35 | 34 |
import us.monoid.json.JSONArray; |
36 | 35 |
import us.monoid.json.JSONException; |
37 |
-import us.monoid.json.JSONObject; |
|
38 |
-import us.monoid.web.Resty; |
|
39 | 36 |
|
40 | 37 |
|
41 |
-public class MarrowActivity extends Activity { |
|
38 |
+public class MarrowActivity extends ActionBarActivity { |
|
42 | 39 |
private TextView userNameText; |
43 | 40 |
private ListView linkList; |
44 |
- private String username; |
|
45 |
- private String password; |
|
46 | 41 |
private String marrowSite; |
47 | 42 |
public SharedPreferences sharedPref; |
48 | 43 |
|
... | ... |
@@ -60,106 +55,86 @@ public class MarrowActivity extends Activity { |
60 | 55 |
} |
61 | 56 |
} |
62 | 57 |
|
63 |
- List<MarrowItem> linkData = new ArrayList<MarrowItem>(); |
|
64 |
- private class GetSubscriptions extends AsyncTask<String, Void, JSONObject> { |
|
65 |
- protected JSONObject doInBackground(String... user) { |
|
66 |
- JSONObject result = new JSONObject(); |
|
67 |
- if (null != user && password != "") { |
|
68 |
- try { |
|
69 |
- result = new Resty() |
|
70 |
- .json(marrowSite.concat("/api/bones/subscriptions")) |
|
71 |
- .toObject(); |
|
72 |
- } catch (IOException | JSONException e) { |
|
73 |
- Log.e("marrow", e.getMessage()); |
|
74 |
- } finally { |
|
75 |
- Log.i("marrow", result.toString()); |
|
76 |
- } |
|
77 |
- } |
|
78 |
- return result; |
|
79 |
- } |
|
58 |
+ private List<MarrowItem> linkData = new ArrayList<MarrowItem>(); |
|
80 | 59 |
|
81 |
- protected void onPostExecute(JSONObject result) { |
|
82 |
- ListView linkList = (ListView) findViewById(R.id.linkList); |
|
83 |
- JSONArray data = new JSONArray(); |
|
84 |
- try { |
|
85 |
- data = result.getJSONArray("marrow"); |
|
86 |
- } catch (JSONException e) { |
|
87 |
- Log.i("marrow", "unexpected JSONException"); |
|
88 |
- e.printStackTrace(); |
|
89 |
- Log.d("marrow", result.toString()); |
|
90 |
- } |
|
91 |
- linkData.clear(); |
|
92 |
- for (int x = 0; x < data.length(); x++) { |
|
93 |
- try { |
|
94 |
- linkData.add( |
|
95 |
- new MarrowItem( |
|
96 |
- data.getJSONObject(x).getString("title"), |
|
97 |
- data.getJSONObject(x).getString("url") |
|
98 |
- ) |
|
99 |
- ); |
|
100 |
- } catch (JSONException e) { |
|
101 |
- e.printStackTrace(); |
|
102 |
- } |
|
103 |
- } |
|
104 |
- ((ArrayAdapter<String>) linkList.getAdapter()).notifyDataSetChanged(); |
|
60 |
+ private class MarrowSite { |
|
61 |
+ private String url; |
|
62 |
+ private List<MarrowItem> data; |
|
105 | 63 |
|
64 |
+ public MarrowSite(String siteUrl, List<Marrow> linkData) { |
|
65 |
+ url = siteUrl; |
|
66 |
+ data = linkData; |
|
106 | 67 |
} |
107 |
- } |
|
108 | 68 |
|
109 |
- private class GetBoneTask extends AsyncTask<String, Void, JSONObject> { |
|
110 |
- protected JSONObject doInBackground(String... user) { |
|
111 |
- JSONObject result = new JSONObject(); |
|
112 |
- if (null != user) { |
|
113 |
- try { |
|
114 |
- result = new Resty() |
|
115 |
- .json(marrowSite.concat("/api/bones/u/").concat(user[0])) |
|
116 |
- .toObject(); |
|
117 |
- } catch (IOException | JSONException e) { |
|
118 |
- Log.e("marrow", e.getMessage()); |
|
119 |
- } finally { |
|
120 |
- Log.i("marrow", result.toString()); |
|
69 |
+ private Deferred<JSONArray, Void, Void> getBone(String uname) { |
|
70 |
+ Deferred<JSONArray, Void, Void> d = new DeferredObject(); |
|
71 |
+ d.done(new DoneCallback<JSONArray>() { |
|
72 |
+ @Override |
|
73 |
+ public void onDone(JSONArray result) { |
|
74 |
+ data.clear(); |
|
75 |
+ for (int x = 0; x < result.length(); x++) { |
|
76 |
+ try { |
|
77 |
+ data.add(new MarrowItem( |
|
78 |
+ result.getJSONObject(x).getString("title"), |
|
79 |
+ result.getJSONObject(x).getString("url") |
|
80 |
+ )); |
|
81 |
+ } catch (JSONException e) { e.printStackTrace(); } |
|
82 |
+ } |
|
83 |
+ |
|
84 |
+ ListView linkList = (ListView) findViewById(R.id.linkList); |
|
85 |
+ ((ArrayAdapter<String>) linkList.getAdapter()).notifyDataSetChanged(); |
|
121 | 86 |
} |
122 |
- } |
|
123 |
- return result; |
|
87 |
+ }); |
|
88 |
+ |
|
89 |
+ new GetBoneTask(d, url).execute(uname); |
|
90 |
+ return d; |
|
124 | 91 |
} |
125 | 92 |
|
126 |
- protected void onPostExecute(JSONObject result) { |
|
127 |
- ListView linkList = (ListView) findViewById(R.id.linkList); |
|
128 |
- JSONArray data = new JSONArray(); |
|
129 |
- try { |
|
130 |
- data = result.getJSONArray("marrow"); |
|
131 |
- } catch (JSONException e) { |
|
132 |
- Log.i("marrow", "unexpected JSONException"); |
|
133 |
- e.printStackTrace(); |
|
134 |
- Log.d("marrow", result.toString()); |
|
135 |
- } |
|
136 |
- linkData.clear(); |
|
137 |
- for (int x = 0; x < data.length(); x++) { |
|
138 |
- try { |
|
139 |
- linkData.add( |
|
140 |
- new MarrowItem( |
|
141 |
- data.getJSONObject(x).getString("title"), |
|
142 |
- data.getJSONObject(x).getString("url") |
|
143 |
- ) |
|
144 |
- ); |
|
145 |
- } catch (JSONException e) { |
|
146 |
- e.printStackTrace(); |
|
93 |
+ private Deferred<JSONArray, Void, Void> getSubscriptions() { |
|
94 |
+ Deferred<JSONArray, Void, Void> d = new DeferredObject<JSONArray, Void, Void>(); |
|
95 |
+ d.done(new DoneCallback<JSONArray>() { |
|
96 |
+ @Override |
|
97 |
+ public void onDone(JSONArray data) { |
|
98 |
+ linkData.clear(); |
|
99 |
+ for (int x = 0; x < data.length(); x++) { |
|
100 |
+ try { |
|
101 |
+ linkData.add( |
|
102 |
+ new MarrowItem( |
|
103 |
+ data.getJSONObject(x).getString("title"), |
|
104 |
+ data.getJSONObject(x).getString("url") |
|
105 |
+ ) |
|
106 |
+ ); |
|
107 |
+ } catch (JSONException e) { |
|
108 |
+ e.printStackTrace(); |
|
109 |
+ } |
|
110 |
+ } |
|
111 |
+ ListView linkList = (ListView) findViewById(R.id.linkList); |
|
112 |
+ ((ArrayAdapter<String>) linkList.getAdapter()).notifyDataSetChanged(); |
|
147 | 113 |
} |
148 |
- } |
|
149 |
- ((ArrayAdapter<String>) linkList.getAdapter()).notifyDataSetChanged(); |
|
114 |
+ }); |
|
115 |
+ |
|
116 |
+ new GetSubscriptions(d, url).execute(); |
|
117 |
+ return d; |
|
150 | 118 |
|
151 | 119 |
} |
152 |
- } |
|
153 | 120 |
|
121 |
+ private Deferred<Boolean, Void, Void> doLogin(String username, String password) { |
|
122 |
+ Deferred<Boolean, Void, Void> waitForLogon = new DeferredObject(); |
|
123 |
+ new LogonTask(waitForLogon, marrowSite).execute(username, password); |
|
124 |
+ return waitForLogon; |
|
125 |
+ } |
|
126 |
+ } |
|
154 | 127 |
public void goButtonClicked(View view) { |
155 | 128 |
String userName = userNameText.getText().toString().trim(); |
156 |
- new GetBoneTask().execute(userName); |
|
129 |
+ getBone(userName); |
|
157 | 130 |
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); |
158 | 131 |
imm.hideSoftInputFromWindow(userNameText.getWindowToken(), 0); |
159 | 132 |
} |
133 |
+ |
|
160 | 134 |
@Override |
161 | 135 |
protected void onCreate(Bundle savedInstanceState) { |
162 | 136 |
super.onCreate(savedInstanceState); |
137 |
+ |
|
163 | 138 |
setContentView(R.layout.activity_marrow); |
164 | 139 |
userNameText = (TextView) findViewById(R.id.userName); |
165 | 140 |
userNameText.setOnEditorActionListener(new TextView.OnEditorActionListener() { |
... | ... |
@@ -175,11 +150,11 @@ public class MarrowActivity extends Activity { |
175 | 150 |
}); |
176 | 151 |
linkList = (ListView) findViewById(R.id.linkList); |
177 | 152 |
linkList.setAdapter( |
178 |
- new ArrayAdapter<MarrowItem>( |
|
179 |
- this, |
|
180 |
- android.R.layout.simple_list_item_1, |
|
181 |
- linkData |
|
182 |
- ) |
|
153 |
+ new ArrayAdapter<MarrowItem>( |
|
154 |
+ this, |
|
155 |
+ android.R.layout.simple_list_item_1, |
|
156 |
+ linkData |
|
157 |
+ ) |
|
183 | 158 |
); |
184 | 159 |
linkList.setOnItemClickListener(new AdapterView.OnItemClickListener() { |
185 | 160 |
@Override |
... | ... |
@@ -193,19 +168,16 @@ public class MarrowActivity extends Activity { |
193 | 168 |
|
194 | 169 |
final MarrowActivity self = this; |
195 | 170 |
sharedPref = PreferenceManager.getDefaultSharedPreferences(this); |
196 |
- username = sharedPref.getString("username", "test"); |
|
197 |
- password = sharedPref.getString("password", ""); |
|
171 |
+ String username = sharedPref.getString("username", "test"); |
|
172 |
+ String password = sharedPref.getString("password", ""); |
|
198 | 173 |
marrowSite = sharedPref.getString("site", "https://joinmarrow.com"); |
199 | 174 |
|
200 | 175 |
if (! password.equals("")) { |
201 |
- Deferred<Boolean, Void, Void> waitForLogon = new DeferredObject(); |
|
202 |
- Promise<Boolean, Void, Void> logonPromise = waitForLogon.promise(); |
|
203 |
- new LogonTask(waitForLogon).execute(username, password, marrowSite); |
|
204 |
- logonPromise.done(new DoneCallback<Boolean>() { |
|
176 |
+ doLogin(username, password).done(new DoneCallback<Boolean>() { |
|
205 | 177 |
@Override |
206 | 178 |
public void onDone(Boolean success) { |
207 | 179 |
if (success) { |
208 |
- new GetSubscriptions().execute(); |
|
180 |
+ getSubscriptions(); |
|
209 | 181 |
} else { |
210 | 182 |
startActivity(new Intent(self, LoginActivity.class)); |
211 | 183 |
} |
... | ... |
@@ -213,7 +185,7 @@ public class MarrowActivity extends Activity { |
213 | 185 |
}).fail(new FailCallback<Void>() { |
214 | 186 |
@Override |
215 | 187 |
public void onFail(Void result) { |
216 |
- new GetBoneTask().execute(username); |
|
188 |
+ getBone(username); |
|
217 | 189 |
} |
218 | 190 |
}); |
219 | 191 |
} |
... | ... |
@@ -229,14 +201,11 @@ public class MarrowActivity extends Activity { |
229 | 201 |
} else if (key.equals("password")) { |
230 | 202 |
Log.i("marrow", "changing Password"); |
231 | 203 |
password = sharedPreferences.getString("password", ""); |
232 |
- Deferred<Boolean, Void, Void> waitForLogon = new DeferredObject<Boolean, Void, Void>(); |
|
233 |
- Promise<Boolean, Void, Void> logonPromise = waitForLogon.promise(); |
|
234 |
- new LogonTask(waitForLogon).execute(); |
|
235 |
- logonPromise.done(new DoneCallback<Boolean>() { |
|
204 |
+ doLogin(username, password).done(new DoneCallback<Boolean>() { |
|
236 | 205 |
@Override |
237 | 206 |
public void onDone(Boolean result) { |
238 | 207 |
if (result) { |
239 |
- new GetSubscriptions().execute(); |
|
208 |
+ getSubscriptions(); |
|
240 | 209 |
} else { |
241 | 210 |
startActivity(new Intent(self, LoginActivity.class)); |
242 | 211 |
} |
... | ... |
@@ -248,6 +217,18 @@ public class MarrowActivity extends Activity { |
248 | 217 |
} |
249 | 218 |
}; |
250 | 219 |
sharedPref.registerOnSharedPreferenceChangeListener(spl); |
220 |
+ |
|
221 |
+ Intent intent = getIntent(); |
|
222 |
+ String action = intent.getAction(); |
|
223 |
+ String type= intent.getType(); |
|
224 |
+ |
|
225 |
+ if (Intent.ACTION_SEND.equals(action)) { |
|
226 |
+ String text = intent.getStringExtra(Intent.EXTRA_TEXT); |
|
227 |
+ if (text != null) { |
|
228 |
+ new AddLink(new DeferredObject(), marrowSite).execute(text, ""); |
|
229 |
+ } |
|
230 |
+ } |
|
231 |
+ |
|
251 | 232 |
} |
252 | 233 |
|
253 | 234 |
|
254 | 235 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,55 @@ |
1 |
+package com.joinmarrow.marrow.tasks; |
|
2 |
+ |
|
3 |
+import android.os.AsyncTask; |
|
4 |
+import android.util.Log; |
|
5 |
+ |
|
6 |
+import org.jdeferred.Deferred; |
|
7 |
+ |
|
8 |
+import java.io.IOException; |
|
9 |
+import java.util.HashMap; |
|
10 |
+ |
|
11 |
+import us.monoid.json.JSONArray; |
|
12 |
+import us.monoid.json.JSONException; |
|
13 |
+import us.monoid.json.JSONObject; |
|
14 |
+import us.monoid.web.Resty; |
|
15 |
+ |
|
16 |
+/** |
|
17 |
+ * Created by edwlan on 4/6/15. |
|
18 |
+ */ |
|
19 |
+public class AddLink extends AsyncTask<String, Void, JSONObject> { |
|
20 |
+ Deferred<JSONObject, JSONObject, Void> taskDeferred; |
|
21 |
+ private String endpoint; |
|
22 |
+ |
|
23 |
+ public AddLink(Deferred d, String url) { |
|
24 |
+ super(); |
|
25 |
+ endpoint = url.concat("/api/bones/add"); |
|
26 |
+ taskDeferred = d; |
|
27 |
+ } |
|
28 |
+ |
|
29 |
+ protected JSONObject doInBackground(String... link) { |
|
30 |
+ String linkToAdd = link[0], |
|
31 |
+ title = ""; |
|
32 |
+ |
|
33 |
+ JSONObject result = new JSONObject(); |
|
34 |
+ try { |
|
35 |
+ Log.i("marrow", "getting"); |
|
36 |
+ |
|
37 |
+ HashMap<String, String> linkInfo = new HashMap<>(); |
|
38 |
+ linkInfo.put("url", linkToAdd); |
|
39 |
+ linkInfo.put("title", title); |
|
40 |
+ JSONObject postData = new JSONObject(linkInfo); |
|
41 |
+ //Log.i("marrow", postData.toString()); |
|
42 |
+ |
|
43 |
+ result = new Resty().json(endpoint, Resty.content(postData)).toObject(); |
|
44 |
+ Log.i("marrow", "gotten"); |
|
45 |
+ } catch (IOException | JSONException e) { |
|
46 |
+ Log.i("marrow", "fail!"); |
|
47 |
+ Log.e("marrow", e.getLocalizedMessage()); |
|
48 |
+ } |
|
49 |
+ return result; |
|
50 |
+ } |
|
51 |
+ |
|
52 |
+ protected void onPostExecute(JSONObject result) { |
|
53 |
+ taskDeferred.resolve(result); |
|
54 |
+ } |
|
55 |
+} |
|
0 | 56 |
\ No newline at end of file |
1 | 57 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,57 @@ |
1 |
+package com.joinmarrow.marrow.tasks; |
|
2 |
+ |
|
3 |
+import android.os.AsyncTask; |
|
4 |
+import android.util.Log; |
|
5 |
+import android.widget.ArrayAdapter; |
|
6 |
+import android.widget.ListView; |
|
7 |
+ |
|
8 |
+import com.joinmarrow.marrow.R; |
|
9 |
+ |
|
10 |
+import org.jdeferred.Deferred; |
|
11 |
+ |
|
12 |
+import java.io.IOException; |
|
13 |
+ |
|
14 |
+import us.monoid.json.JSONArray; |
|
15 |
+import us.monoid.json.JSONException; |
|
16 |
+import us.monoid.json.JSONObject; |
|
17 |
+import us.monoid.web.Resty; |
|
18 |
+ |
|
19 |
+/** |
|
20 |
+ * Created by edwlan on 4/5/15. |
|
21 |
+ */ |
|
22 |
+public class GetBoneTask extends AsyncTask<String, Void, JSONObject> { |
|
23 |
+ Deferred taskDeferred; |
|
24 |
+ private String endpoint; |
|
25 |
+ |
|
26 |
+ public GetBoneTask(Deferred d, String url) { |
|
27 |
+ super(); |
|
28 |
+ endpoint = url.concat("/api/bones/u/"); |
|
29 |
+ taskDeferred = d; |
|
30 |
+ } |
|
31 |
+ |
|
32 |
+ protected JSONObject doInBackground(String... user) { |
|
33 |
+ JSONObject result = new JSONObject(); |
|
34 |
+ if (null != user) { |
|
35 |
+ try { |
|
36 |
+ result = new Resty().json(endpoint.concat(user[0])).toObject(); |
|
37 |
+ } catch (IOException | JSONException e) { |
|
38 |
+ Log.e("marrow", e.getMessage()); |
|
39 |
+ } finally { |
|
40 |
+ Log.i("marrow", result.toString()); |
|
41 |
+ } |
|
42 |
+ } |
|
43 |
+ return result; |
|
44 |
+ } |
|
45 |
+ //TODO: use deferred to trigger view update |
|
46 |
+ protected void onPostExecute(JSONObject result) { |
|
47 |
+ JSONArray data = new JSONArray(); |
|
48 |
+ try { |
|
49 |
+ data = result.getJSONArray("marrow"); |
|
50 |
+ } catch (JSONException e) { |
|
51 |
+ Log.i("marrow", "unexpected JSONException"); |
|
52 |
+ e.printStackTrace(); |
|
53 |
+ Log.d("marrow", result.toString()); |
|
54 |
+ } |
|
55 |
+ taskDeferred.resolve(data); |
|
56 |
+ } |
|
57 |
+} |
|
0 | 58 |
\ No newline at end of file |
1 | 59 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,57 @@ |
1 |
+package com.joinmarrow.marrow.tasks; |
|
2 |
+ |
|
3 |
+import android.os.AsyncTask; |
|
4 |
+import android.util.Log; |
|
5 |
+import android.widget.ArrayAdapter; |
|
6 |
+import android.widget.ListView; |
|
7 |
+ |
|
8 |
+import com.joinmarrow.marrow.R; |
|
9 |
+ |
|
10 |
+import org.jdeferred.Deferred; |
|
11 |
+ |
|
12 |
+import java.io.IOException; |
|
13 |
+ |
|
14 |
+import us.monoid.json.JSONArray; |
|
15 |
+import us.monoid.json.JSONException; |
|
16 |
+import us.monoid.json.JSONObject; |
|
17 |
+import us.monoid.web.Resty; |
|
18 |
+ |
|
19 |
+/** |
|
20 |
+ * Created by edwlan on 4/6/15. |
|
21 |
+ */ |
|
22 |
+public class GetSubscriptions extends AsyncTask<Void, Void, JSONObject> { |
|
23 |
+ Deferred<JSONArray, Void, Void> taskDeferred; |
|
24 |
+ private String endpoint; |
|
25 |
+ |
|
26 |
+ public GetSubscriptions(Deferred d, String url) { |
|
27 |
+ taskDeferred = d; |
|
28 |
+ endpoint = url.concat("/api/bones/subscriptions"); |
|
29 |
+ } |
|
30 |
+ |
|
31 |
+ @Override |
|
32 |
+ protected JSONObject doInBackground(Void... loginData) { |
|
33 |
+ JSONObject result = new JSONObject(); |
|
34 |
+ try { |
|
35 |
+ result = new Resty().json(endpoint).toObject(); |
|
36 |
+ } catch (IOException | JSONException e) { |
|
37 |
+ Log.e("marrow", e.getMessage()); |
|
38 |
+ } finally { |
|
39 |
+ Log.i("marrow", result.toString()); |
|
40 |
+ } |
|
41 |
+ return result; |
|
42 |
+ } |
|
43 |
+ |
|
44 |
+ @Override |
|
45 |
+ protected void onPostExecute(JSONObject result) { |
|
46 |
+ JSONArray data = new JSONArray(); |
|
47 |
+ try { |
|
48 |
+ data = result.getJSONArray("marrow"); |
|
49 |
+ } catch (JSONException e) { |
|
50 |
+ Log.i("marrow", "unexpected JSONException"); |
|
51 |
+ e.printStackTrace(); |
|
52 |
+ Log.d("marrow", result.toString()); |
|
53 |
+ } |
|
54 |
+ taskDeferred.resolve(data); |
|
55 |
+ } |
|
56 |
+} |
|
57 |
+ |
... | ... |
@@ -1,6 +1,14 @@ |
1 | 1 |
<menu xmlns:android="http://schemas.android.com/apk/res/android" |
2 | 2 |
xmlns:app="http://schemas.android.com/apk/res-auto" |
3 | 3 |
xmlns:tools="http://schemas.android.com/tools" tools:context=".MarrowActivity"> |
4 |
+ <item android:id="@+id/action_search" |
|
5 |
+ android:icon="@drawable/ic_action_search" |
|
6 |
+ android:title="@string/action_search" |
|
7 |
+ android:showAsAction="ifRoom" /> |
|
8 |
+ <item android:id="@+id/action_add" |
|
9 |
+ android:icon="@drawable/ic_action_new" |
|
10 |
+ android:title="@string/action_new" |
|
11 |
+ android:showAsAction="ifRoom" /> |
|
4 | 12 |
<item android:id="@+id/action_settings" android:title="@string/action_settings" |
5 | 13 |
android:orderInCategory="100" /> |
6 | 14 |
</menu> |
... | ... |
@@ -2,6 +2,9 @@ |
2 | 2 |
<string name="app_name">Marrow</string> |
3 | 3 |
|
4 | 4 |
<string name="action_settings">Settings</string> |
5 |
+ <string name="action_search">Find Bone</string> |
|
6 |
+ <string name="action_new">Add Link</string> |
|
7 |
+ |
|
5 | 8 |
<string name="username">Username</string> |
6 | 9 |
<string name="password">Password</string> |
7 | 10 |
<string name="site">Site URL (do not change)</string> |