summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorstom79 <tschneider.ac@gmail.com>2018-11-06 19:50:09 +0100
committerstom79 <tschneider.ac@gmail.com>2018-11-06 19:50:09 +0100
commitd53befdbf91f79b5b7d7faada5a1aca1443bc0cd (patch)
treebebf133d13ee3a92ff2964966cd8ae04b4cb5552 /app
parent204e2fc69d89c403f24f2a5238e9b1439651d9b8 (diff)
Possibility to check who boosted or added to fav a toot - #549
Diffstat (limited to 'app')
-rw-r--r--app/src/main/AndroidManifest.xml5
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/TootInfoActivity.java156
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java10
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/client/API.java78
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java11
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java6
-rw-r--r--app/src/main/res/layout/activity_toot_info.xml42
-rw-r--r--app/src/main/res/menu/option_toot.xml4
-rw-r--r--app/src/main/res/values/strings.xml1
9 files changed, 309 insertions, 4 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index c3afc39d9..5f97632e6 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -124,6 +124,11 @@
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
/>
+ <activity android:name=".activities.TootInfoActivity"
+ android:windowSoftInputMode="stateAlwaysHidden"
+ android:configChanges="orientation|screenSize"
+ android:label="@string/app_name"
+ />
<activity android:name=".activities.HashTagActivity"
android:windowSoftInputMode="stateAlwaysHidden"
android:configChanges="orientation|screenSize"
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootInfoActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootInfoActivity.java
new file mode 100644
index 000000000..d658e380b
--- /dev/null
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootInfoActivity.java
@@ -0,0 +1,156 @@
+/* Copyright 2017 Thomas Schneider
+ *
+ * This file is a part of Mastalab
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Mastalab; if not,
+ * see <http://www.gnu.org/licenses>. */
+package fr.gouv.etalab.mastodon.activities;
+
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.support.design.widget.NavigationView;
+import android.support.design.widget.TabLayout;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentStatePagerAdapter;
+import android.support.v4.view.PagerAdapter;
+import android.support.v4.view.ViewPager;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TableLayout;
+import android.widget.Toast;
+
+import fr.gouv.etalab.mastodon.R;
+import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
+import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
+import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
+import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
+import fr.gouv.etalab.mastodon.fragments.TabLayoutTootsFragment;
+import fr.gouv.etalab.mastodon.helper.Helper;
+
+
+
+/**
+ * Created by Thomas on 05/11/2018.
+ * Toot info activity class
+ */
+
+public class TootInfoActivity extends BaseActivity {
+
+
+ private String toot_id;
+ private TabLayout tabLayout;
+ private ViewPager mPager;
+ private String userID;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+ SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
+ int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
+ switch (theme){
+ case Helper.THEME_LIGHT:
+ setTheme(R.style.AppTheme);
+ break;
+ case Helper.THEME_DARK:
+ setTheme(R.style.AppThemeDark);
+ break;
+ case Helper.THEME_BLACK:
+ setTheme(R.style.AppThemeBlack);
+ break;
+ default:
+ setTheme(R.style.AppThemeDark);
+ }
+ setContentView(R.layout.activity_toot_info);
+ getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+ Bundle b = getIntent().getExtras();
+ if( getSupportActionBar() != null)
+ getSupportActionBar().hide();
+ if( b != null){
+ toot_id = b.getString("toot_id", null);
+ }
+ if( toot_id == null){
+ Toast.makeText(this, R.string.toast_error, Toast.LENGTH_SHORT).show();
+ finish();
+ }
+ userID = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
+ tabLayout = findViewById(R.id.tabLayout);
+ mPager = findViewById(R.id.viewpager);
+ tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.reblog)));
+ tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.favourite)));
+
+ PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
+ mPager.setAdapter(mPagerAdapter);
+
+ mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+
+ }
+
+ @Override
+ public void onPageSelected(int position) {
+ TabLayout.Tab tab = tabLayout.getTabAt(position);
+ if( tab != null)
+ tab.select();
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int state) {
+
+ }
+ });
+ }
+
+
+ private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
+
+ ScreenSlidePagerAdapter(FragmentManager fm) {
+ super(fm);
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ Bundle bundle = new Bundle();
+ switch (position){
+ case 0:
+ DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment();
+ bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.REBLOGGED);
+ bundle.putString("targetedId", toot_id);
+ displayAccountsFragment.setArguments(bundle);
+ return displayAccountsFragment;
+ case 1:
+ displayAccountsFragment = new DisplayAccountsFragment();
+ bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FAVOURITED);
+ bundle.putString("targetedId", toot_id);
+ displayAccountsFragment.setArguments(bundle);
+ return displayAccountsFragment;
+ }
+ return null;
+ }
+
+
+ @Override
+ public int getCount() {
+ return 2;
+
+ }
+ }
+
+
+}
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java
index 65e112ca2..2a20d533c 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java
@@ -44,7 +44,9 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
MUTED,
FOLLOWING,
FOLLOWERS,
- CHANNELS
+ CHANNELS,
+ REBLOGGED,
+ FAVOURITED
}
public RetrieveAccountsAsyncTask(Context context, String instance, String name, OnRetrieveAccountsInterface onRetrieveAccountsInterface){
@@ -75,6 +77,12 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
API api = new API(this.contextReference.get());
switch (action){
+ case REBLOGGED:
+ apiResponse = api.getRebloggedBy(targetedId, max_id);
+ break;
+ case FAVOURITED:
+ apiResponse = api.getFavouritedBy(targetedId, max_id);
+ break;
case BLOCKED:
apiResponse = api.getBlocks(max_id);
break;
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 4fa1fb769..cdb00fe67 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
@@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.client;
import android.content.Context;
import android.content.SharedPreferences;
+import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
@@ -432,6 +433,83 @@ public class API {
}
+
+ /**
+ * Retrieves accounts that reblogged the status *synchronously*
+ *
+ * @param statusId String Id of the status
+ * @param max_id String id max
+ * @return APIResponse
+ */
+ @SuppressWarnings("SameParameterValue")
+ public APIResponse getRebloggedBy(String statusId, String max_id) {
+
+ HashMap<String, String> params = new HashMap<>();
+ if (max_id != null)
+ params.put("max_id", max_id);
+ params.put("limit", "80");
+ accounts = new ArrayList<>();
+ try {
+ HttpsConnection httpsConnection = new HttpsConnection(context);
+ String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s/reblogged_by", statusId)), 60, params, prefKeyOauthTokenT);
+ accounts = parseAccountResponse(new JSONArray(response));
+ apiResponse.setSince_id(httpsConnection.getSince_id());
+ apiResponse.setMax_id(httpsConnection.getMax_id());
+ } catch (HttpsConnection.HttpsConnectionException e) {
+ setError(e.getStatusCode(), e);
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (KeyManagementException e) {
+ e.printStackTrace();
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ apiResponse.setAccounts(accounts);
+ return apiResponse;
+ }
+
+
+ /**
+ * Retrieves accounts that favourited the status *synchronously*
+ *
+ * @param statusId String Id of the status
+ * @param max_id String id max
+ * @return APIResponse
+ */
+ @SuppressWarnings("SameParameterValue")
+ public APIResponse getFavouritedBy(String statusId, String max_id) {
+
+ HashMap<String, String> params = new HashMap<>();
+ if (max_id != null)
+ params.put("max_id", max_id);
+ params.put("limit", "80");
+ accounts = new ArrayList<>();
+ try {
+ HttpsConnection httpsConnection = new HttpsConnection(context);
+ String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s/favourited_by", statusId)), 60, params, prefKeyOauthTokenT);
+ accounts = parseAccountResponse(new JSONArray(response));
+ apiResponse.setSince_id(httpsConnection.getSince_id());
+ apiResponse.setMax_id(httpsConnection.getMax_id());
+ } catch (HttpsConnection.HttpsConnectionException e) {
+ setError(e.getStatusCode(), e);
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (KeyManagementException e) {
+ e.printStackTrace();
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ apiResponse.setAccounts(accounts);
+ return apiResponse;
+ }
+
+
/**
* Retrieves one status *synchronously*
*
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java
index f085e4887..5a07a465a 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java
@@ -91,6 +91,7 @@ import fr.gouv.etalab.mastodon.activities.MediaActivity;
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
import fr.gouv.etalab.mastodon.activities.ShowConversationActivity;
import fr.gouv.etalab.mastodon.activities.TootActivity;
+import fr.gouv.etalab.mastodon.activities.TootInfoActivity;
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
@@ -1342,6 +1343,16 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
//noinspection deprecation
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
+ case R.id.action_info:
+ Intent intent = new Intent(context, TootInfoActivity.class);
+ Bundle b = new Bundle();
+ if( status.getReblog() != null)
+ b.putString("toot_id", status.getReblog().getId());
+ else
+ b.putString("toot_id", status.getId());
+ intent.putExtras(b);
+ context.startActivity(intent);
+ return true;
case R.id.action_open_browser:
Helper.openBrowser(context, status.getReblog()!=null?status.getReblog().getUrl():status.getUrl());
return true;
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java
index c75152ebc..64021bf28 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java
@@ -110,7 +110,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
if (firstVisibleItem + visibleItemCount == totalItemCount) {
if (!flag_loading) {
flag_loading = true;
- if (type == RetrieveAccountsAsyncTask.Type.FOLLOWERS || type == RetrieveAccountsAsyncTask.Type.FOLLOWING)
+ if (type == RetrieveAccountsAsyncTask.Type.FOLLOWERS || type == RetrieveAccountsAsyncTask.Type.FOLLOWING || type == RetrieveAccountsAsyncTask.Type.REBLOGGED || type == RetrieveAccountsAsyncTask.Type.FAVOURITED)
asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if (type == RetrieveAccountsAsyncTask.Type.CHANNELS)
asyncTask = new RetrieveAccountsAsyncTask(context, instance, name, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@@ -132,7 +132,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
firstLoad = true;
flag_loading = true;
swiped = true;
- if (type == RetrieveAccountsAsyncTask.Type.FOLLOWERS || type == RetrieveAccountsAsyncTask.Type.FOLLOWING)
+ if (type == RetrieveAccountsAsyncTask.Type.FOLLOWERS || type == RetrieveAccountsAsyncTask.Type.FOLLOWING|| type == RetrieveAccountsAsyncTask.Type.REBLOGGED || type == RetrieveAccountsAsyncTask.Type.FAVOURITED)
asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if (type == RetrieveAccountsAsyncTask.Type.CHANNELS)
asyncTask = new RetrieveAccountsAsyncTask(context, instance, name, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@@ -163,7 +163,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
break;
}
- if (type == RetrieveAccountsAsyncTask.Type.FOLLOWERS || type == RetrieveAccountsAsyncTask.Type.FOLLOWING)
+ if (type == RetrieveAccountsAsyncTask.Type.FOLLOWERS || type == RetrieveAccountsAsyncTask.Type.FOLLOWING|| type == RetrieveAccountsAsyncTask.Type.REBLOGGED || type == RetrieveAccountsAsyncTask.Type.FAVOURITED)
asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if (type == RetrieveAccountsAsyncTask.Type.CHANNELS)
asyncTask = new RetrieveAccountsAsyncTask(context, instance, name, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
diff --git a/app/src/main/res/layout/activity_toot_info.xml b/app/src/main/res/layout/activity_toot_info.xml
new file mode 100644
index 000000000..d211e8f9f
--- /dev/null
+++ b/app/src/main/res/layout/activity_toot_info.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2018 Thomas Schneider
+
+ This file is a part of Mastalab
+
+ This program is free software; you can redistribute it and/or modify it under the terms of the
+ GNU General Public License as published by the Free Software Foundation; either version 3 of the
+ License, or (at your option) any later version.
+
+ Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with Mastalab; if not,
+ see <http://www.gnu.org/licenses>.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:fitsSystemWindows="true"
+ tools:context="fr.gouv.etalab.mastodon.activities.InstanceHealthActivity"
+ android:layout_margin="@dimen/fab_margin"
+ android:id="@+id/container"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ <android.support.design.widget.TabLayout
+ android:id="@+id/tabLayout"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ app:tabSelectedTextColor="?attr/colorAccent"
+ app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
+ app:tabMode="fixed"
+ app:tabGravity="fill"
+ />
+ <android.support.v4.view.ViewPager
+ android:id="@+id/viewpager"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ />
+</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/menu/option_toot.xml b/app/src/main/res/menu/option_toot.xml
index 52d23b151..1017fc36e 100644
--- a/app/src/main/res/menu/option_toot.xml
+++ b/app/src/main/res/menu/option_toot.xml
@@ -11,6 +11,10 @@
android:actionLayout="@layout/bookmark_layout"
app:showAsAction="never" />
<item
+ android:id="@+id/action_info"
+ android:title="@string/information"
+ app:showAsAction="never" />
+ <item
android:id="@+id/action_open_browser"
android:title="@string/action_open_in_web"
app:showAsAction="never"/>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 2cc25f1a8..c3f04091d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -654,6 +654,7 @@
<string name="videos">Videos</string>
<string name="channels">Channels</string>
<string name="set_display_emoji">Use Emoji One</string>
+ <string name="information">information</string>
<string-array name="filter_expire">
<item>Never</item>