Possibility to check who boosted or added to fav a toot - #549

This commit is contained in:
stom79 2018-11-06 19:50:09 +01:00
parent 204e2fc69d
commit d53befdbf9
9 changed files with 309 additions and 4 deletions

View File

@ -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"

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -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*
*

View File

@ -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;

View File

@ -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);

View File

@ -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>

View File

@ -10,6 +10,10 @@
android:title="@string/bookmark_add"
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"

View File

@ -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>