diff options
author | tom79 <tschneider.ac@gmail.com> | 2019-05-11 19:58:41 +0200 |
---|---|---|
committer | tom79 <tschneider.ac@gmail.com> | 2019-05-11 19:58:41 +0200 |
commit | 3629f4a137b356d3b0ef940d293984a92b479457 (patch) | |
tree | 18835b41d7c7f75a0a99313dc3190ce4b6acc0a9 /app | |
parent | f8d823360e239232d2f8918365f6b5c39ce58d7c (diff) |
Follow GNU Social instances
Diffstat (limited to 'app')
10 files changed, 75 insertions, 10 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index fbf2cecab..eb83792a5 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -53,7 +53,6 @@ import android.support.v7.widget.PopupMenu; import android.support.v7.widget.SearchView; import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.Toolbar; -import android.util.Log; import android.util.Patterns; import android.view.Gravity; import android.view.LayoutInflater; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ReorderTimelinesActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ReorderTimelinesActivity.java index 3b0990b84..ba5988728 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ReorderTimelinesActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ReorderTimelinesActivity.java @@ -187,7 +187,10 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra new HttpsConnection(ReorderTimelinesActivity.this).get("https://" + instanceName + "/api/v1/timelines/public", 10, null, null); }else if( radioGroup.getCheckedRadioButtonId() == R.id.misskey_instance) { new HttpsConnection(ReorderTimelinesActivity.this).post("https://" + instanceName + "/api/notes/local-timeline", 10, null, null); + }else if( radioGroup.getCheckedRadioButtonId() == R.id.gnu_instance) { + new HttpsConnection(ReorderTimelinesActivity.this).get("https://" + instanceName + "/api/statuses/public_timeline.json", 10, null, null); } + runOnUiThread(new Runnable() { public void run() { dialog.dismiss(); @@ -199,6 +202,8 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra new InstancesDAO(ReorderTimelinesActivity.this, db).insertInstance(instanceName, "PIXELFED"); } else if( radioGroup.getCheckedRadioButtonId() == R.id.misskey_instance) { new InstancesDAO(ReorderTimelinesActivity.this, db).insertInstance(instanceName, "MISSKEY"); + }else if( radioGroup.getCheckedRadioButtonId() == R.id.gnu_instance) { + new InstancesDAO(ReorderTimelinesActivity.this, db).insertInstance(instanceName, "GNU"); } if( timelines != null && adapter != null) { List<RemoteInstance> instance = new InstancesDAO(ReorderTimelinesActivity.this, db).getInstanceByName(instanceName); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java index 9f224caa9..6279f1c3b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java @@ -18,6 +18,7 @@ import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.os.AsyncTask; + import java.lang.ref.WeakReference; import java.util.List; @@ -232,6 +233,8 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> { } } else if(remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("PIXELFED") ) { apiResponse = api.getPixelfedTimeline(instanceName, max_id); + } else if(remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("GNU") ) { + apiResponse = api.getGNUTimeline(instanceName, max_id); }else { apiResponse = api.getPeertube(this.instanceName, max_id); } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index e4a2d98aa..3162eca2c 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -1025,6 +1025,40 @@ public class API { } + /** + * Retrieves public GNU timeline for the account *synchronously* + * @param max_id String id max + * @return APIResponse + */ + public APIResponse getGNUTimeline(String remoteInstance, String max_id) { + + HashMap<String, String> params = new HashMap<>(); + if (max_id != null) + params.put("max_id", max_id); + statuses = new ArrayList<>(); + try { + HttpsConnection httpsConnection = new HttpsConnection(context); + String response = httpsConnection.get("https://"+remoteInstance+"/api/statuses/public_timeline.json", 60, params, prefKeyOauthTokenT); + statuses = GNUAPI.parseStatuses(context, new JSONArray(response)); + if( statuses.size() > 0) { + apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1)); + apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId())-1)); + } + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } catch (HttpsConnection.HttpsConnectionException e) { + e.printStackTrace(); + } + apiResponse.setStatuses(statuses); + return apiResponse; + } + /** * Retrieves public pixelfed timeline for the account *synchronously* diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/GNUAPI.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/GNUAPI.java index 3ea5041cc..4e4891b9a 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/GNUAPI.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/GNUAPI.java @@ -1823,7 +1823,7 @@ public class GNUAPI { * @param jsonArray JSONArray * @return List<Status> */ - private List<Status> parseStatuses(Context context, JSONArray jsonArray){ + public static List<Status> parseStatuses(Context context, JSONArray jsonArray){ List<Status> statuses = new ArrayList<>(); try { @@ -1848,7 +1848,7 @@ public class GNUAPI { * @return Status */ @SuppressWarnings("InfiniteRecursion") - private Status parseStatuses(Context context, JSONObject resobj){ + private static Status parseStatuses(Context context, JSONObject resobj){ Status status = new Status(); try { status.setId(resobj.get("id").toString()); @@ -1953,6 +1953,8 @@ public class GNUAPI { if( resobj.has("friendica_activities") && resobj.getJSONObject("friendica_activities").has("like")){ status.setFavourited(false); JSONArray jsonArray = resobj.getJSONObject("friendica_activities").getJSONArray("like"); + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); for (int i = 0; i < jsonArray.length(); i++) { JSONObject like = jsonArray.getJSONObject(i); if( like.getString("id").equals(userId)) { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/ReorderTabAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/ReorderTabAdapter.java index 99674280c..37913f97b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/ReorderTabAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/ReorderTabAdapter.java @@ -128,6 +128,9 @@ public class ReorderTabAdapter extends RecyclerView.Adapter<ReorderTabAdapter.It case "MISSKEY": holder.iconView.setImageResource(R.drawable.misskey); break; + case "GNU": + holder.iconView.setImageResource(R.drawable.ic_gnu_social); + break; } holder.textView.setText( tl.getRemoteInstance().getHost()); break; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index d3317db99..47e87adba 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -198,7 +198,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn lastReadToot = sharedpreferences.getString(Helper.LAST_READ_TOOT_ID + userId + instance, null); lastReadTootDate = Helper.stringToDate(context, sharedpreferences.getString(Helper.LAST_READ_TOOT_DATE + userId + instance, null)); } - if( instanceType == null || instanceType.equals("MASTODON") || instanceType.equals("MISSKEY") ){ + if( instanceType == null || instanceType.equals("MASTODON") || instanceType.equals("MISSKEY") || instanceType.equals("GNU") ){ if( type == RetrieveFeedsAsyncTask.Type.TAG && tag != null) { BaseMainActivity.displayPeertube = null; List<TagTimeline> tagTimelines = new SearchDAO(context, db).getTimelineInfo(tag); @@ -542,7 +542,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn } //Let's deal with statuses if( statuses != null && statuses.size() > 0) { - if ( statusListAdapter != null && ( instanceType.equals("MASTODON") || instanceType.equals("MISSKEY"))) { + if ( statusListAdapter != null && ( instanceType.equals("MASTODON") || instanceType.equals("MISSKEY") || instanceType.equals("GNU"))) { this.statuses.addAll(statuses); statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size()); }else if(artListAdapter != null && instanceType.equals("ART") ) { @@ -824,7 +824,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn public void scrollToTop(){ if( lv_status != null && instanceType != null) { - if( statusListAdapter != null && (instanceType.equals("MASTODON") || instanceType.equals("MISSKEY"))) + if( statusListAdapter != null && (instanceType.equals("MASTODON") || instanceType.equals("MISSKEY") || instanceType.equals("GNU"))) lv_status.setAdapter(statusListAdapter); else if( pixelfedListAdapter != null && instanceType.equals("PIXELFED")) lv_status.setAdapter(pixelfedListAdapter); @@ -840,7 +840,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn */ public void refreshFilter(){ - if( instanceType.equals("MASTODON") || instanceType.equals("MISSKEY")) + if( instanceType.equals("MASTODON") || instanceType.equals("MISSKEY")|| instanceType.equals("GNU")) statusListAdapter.notifyDataSetChanged(); else if( instanceType.equals("PIXELFED")) pixelfedListAdapter.notifyDataSetChanged(); @@ -857,7 +857,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn for (Status status : this.statuses) { status.setNew(false); } - if( instanceType.equals("MASTODON") || instanceType.equals("MISSKEY")) + if( instanceType.equals("MASTODON") || instanceType.equals("MISSKEY")|| instanceType.equals("GNU")) statusListAdapter.notifyItemRangeChanged(0, this.statuses.size()); else if( instanceType.equals("PIXELFED")) pixelfedListAdapter.notifyItemRangeChanged(0, this.statuses.size()); @@ -881,7 +881,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn Status status = it.next(); for (Status status1 : statuses) { if (status.getConversationId() != null && status.getConversationId().equals(status1.getConversationId())) { - if( instanceType.equals("MASTODON") || instanceType.equals("MISSKEY")) + if( instanceType.equals("MASTODON") || instanceType.equals("MISSKEY")|| instanceType.equals("GNU")) statusListAdapter.notifyItemRemoved(position); else if( instanceType.equals("PIXELFED")) pixelfedListAdapter.notifyItemRemoved(position); @@ -920,7 +920,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn } } } - if( statusListAdapter != null && (instanceType.equals("MASTODON") || instanceType.equals("MISSKEY"))) + if( statusListAdapter != null && (instanceType.equals("MASTODON") || instanceType.equals("MISSKEY")|| instanceType.equals("GNU"))) statusListAdapter.notifyItemRangeInserted(0, inserted); else if( pixelfedListAdapter != null && instanceType.equals("PIXELFED")) pixelfedListAdapter.notifyItemRangeInserted(0, inserted); diff --git a/app/src/main/res/drawable/ic_gnu_social.xml b/app/src/main/res/drawable/ic_gnu_social.xml new file mode 100644 index 000000000..a14c90623 --- /dev/null +++ b/app/src/main/res/drawable/ic_gnu_social.xml @@ -0,0 +1,13 @@ +<vector android:height="24dp" android:viewportHeight="50" + android:viewportWidth="46" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillAlpha="1" android:fillColor="#a22430" + android:pathData="m35.7851,38.8496c-1.9018,11.0937 -19.5461,11.1503 -19.5461,11.1503 0,0 10.7949,-3.3447 10.0553,-11.3745 -0.6756,-7.3353 9.4908,0.2241 9.4908,0.2241z" android:strokeColor="#00000000"/> + <path android:fillAlpha="1" android:fillColor="#a22430" + android:pathData="M6.7862,-0L39.2138,-0A6.5744,6.5744 0,0 1,45.7882 6.5744L45.7882,32.857A6.5744,6.5744 0,0 1,39.2138 39.4314L6.7862,39.4314A6.5744,6.5744 0,0 1,0.2118 32.857L0.2118,6.5744A6.5744,6.5744 0,0 1,6.7862 -0z" android:strokeColor="#00000000"/> + <path android:fillAlpha="1" android:fillColor="#ffffff" + android:pathData="m24.6405,23.3869 l9.1892,0c0,0 0,-4.4078 0,0 0,4.4078 -1.8677,11.2811 -10.6087,10.8328 -8.741,-0.4483 -10.6834,-7.3215 -10.7581,-11.9535 -0.0747,-4.632 1.3478,-10.3478 11.6546,-10.0857 8.8157,0.2241 9.6375,8.2927 9.6375,8.2927l-4.2584,-0.0747c0,0 -0.9712,-4.4078 -6.1262,-4.1837 -5.1549,0.2241 -5.8273,1.1206 -5.8273,6.5744 0,5.4538 2.3904,7.3283 6.0514,7.4709 5.7526,0.2241 5.2296,-2.9884 5.2296,-2.9884l-2.6895,0.1494z" android:strokeColor="#00000000"/> + <path android:fillAlpha="1" android:fillColor="#ffffff" + android:pathData="m29.2795,5.3446c0.6983,-0.6228 3.6981,3.0257 3.7728,4.4452 0.1099,2.089 0.1653,5.8854 -6.0514,5.8273 -3.9969,-0.0374 -4.1837,-2.7642 -4.1837,-2.7642 0,0 -0.1121,-2.3533 2.0545,-2.3533 2.1666,0 1.4552,1.5315 3.1751,1.5315 2.5775,0 2.1757,-1.0455 2.2413,-2.3907 0.1494,-3.0631 -1.7068,-3.673 -1.0086,-4.2958z" android:strokeColor="#00000000"/> + <path android:fillAlpha="1" android:fillColor="#ffffff" + android:pathData="m16.5783,5.3446c-0.6983,-0.6228 -3.7728,2.3533 -3.7728,4.4452 0,2.0919 -0.1653,5.8854 6.0514,5.8273 3.9969,-0.0374 4.1837,-2.7642 4.1837,-2.7642 0,0 0.1121,-2.3533 -2.0545,-2.3533 -2.1666,0 -1.4552,1.5315 -3.1751,1.5315 -2.5775,0 -2.1757,-1.0455 -2.2413,-2.3907 -0.1494,-3.0631 1.7068,-3.673 1.0086,-4.2958z" android:strokeColor="#00000000"/> +</vector> diff --git a/app/src/main/res/layout/search_instance.xml b/app/src/main/res/layout/search_instance.xml index ce2d5b894..81cca530c 100644 --- a/app/src/main/res/layout/search_instance.xml +++ b/app/src/main/res/layout/search_instance.xml @@ -36,5 +36,10 @@ android:layout_height="wrap_content" android:text="@string/misskey_instance" /> + <RadioButton android:id="@+id/gnu_instance" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/gnu_instance" + /> </RadioGroup> </LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fc6b2d299..59892bd9a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -944,6 +944,7 @@ <string name="action_bbcode">BBCode</string> <string name="add_timeline">Add a timeline</string> <string name="set_sensitive_content">Always mark media as sensitive</string> + <string name="gnu_instance">GNU instance</string> <plurals name="number_of_vote"> <item quantity="one">%d vote</item> |