Limits cross-account actions to usual timelines (ie: removes them from notification timeline)
This commit is contained in:
parent
6768f382a8
commit
563bb53f40
|
@ -455,7 +455,7 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if( status != null)
|
||||
CrossActions.doCrossAction(context, status, status.isFavourited()? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, notificationsListAdapter, NotificationsListAdapter.this);
|
||||
CrossActions.doCrossAction(context, status, status.isFavourited()? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, notificationsListAdapter, NotificationsListAdapter.this, true);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -463,7 +463,7 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if( status != null)
|
||||
CrossActions.doCrossAction(context, status, status.isReblogged()? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, notificationsListAdapter, NotificationsListAdapter.this);
|
||||
CrossActions.doCrossAction(context, status, status.isReblogged()? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, notificationsListAdapter, NotificationsListAdapter.this, true);
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -730,40 +730,42 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
|
|||
notifications.removeAll(notificationsToRemove);
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
if( statusAction == API.StatusAction.REBLOG){
|
||||
for(Notification notification: notifications){
|
||||
if( notification.getStatus().getId().equals(targetedId)) {
|
||||
notification.getStatus().setReblogs_count(notification.getStatus().getReblogs_count() + 1);
|
||||
break;
|
||||
if( targetedId != null) {
|
||||
if (statusAction == API.StatusAction.REBLOG) {
|
||||
for (Notification notification : notifications) {
|
||||
if (notification.getStatus().getId().equals(targetedId)) {
|
||||
notification.getStatus().setReblogs_count(notification.getStatus().getReblogs_count() + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
}else if( statusAction == API.StatusAction.UNREBLOG){
|
||||
for(Notification notification: notifications){
|
||||
if( notification.getStatus().getId().equals(targetedId)) {
|
||||
if( notification.getStatus().getReblogs_count() - 1 >= 0 )
|
||||
notification.getStatus().setReblogs_count(notification.getStatus().getReblogs_count() - 1);
|
||||
break;
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
} else if (statusAction == API.StatusAction.UNREBLOG) {
|
||||
for (Notification notification : notifications) {
|
||||
if (notification.getStatus().getId().equals(targetedId)) {
|
||||
if (notification.getStatus().getReblogs_count() - 1 >= 0)
|
||||
notification.getStatus().setReblogs_count(notification.getStatus().getReblogs_count() - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
}else if( statusAction == API.StatusAction.FAVOURITE){
|
||||
for(Notification notification: notifications){
|
||||
if( notification.getStatus().getId().equals(targetedId)) {
|
||||
notification.getStatus().setFavourites_count(notification.getStatus().getFavourites_count() + 1);
|
||||
break;
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
} else if (statusAction == API.StatusAction.FAVOURITE) {
|
||||
for (Notification notification : notifications) {
|
||||
if (notification.getStatus().getId().equals(targetedId)) {
|
||||
notification.getStatus().setFavourites_count(notification.getStatus().getFavourites_count() + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
}else if( statusAction == API.StatusAction.UNFAVOURITE){
|
||||
for(Notification notification: notifications){
|
||||
if( notification.getStatus().getId().equals(targetedId)) {
|
||||
if( notification.getStatus().getFavourites_count() - 1 >= 0 )
|
||||
notification.getStatus().setFavourites_count(notification.getStatus().getFavourites_count() - 1);
|
||||
break;
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
} else if (statusAction == API.StatusAction.UNFAVOURITE) {
|
||||
for (Notification notification : notifications) {
|
||||
if (notification.getStatus().getId().equals(targetedId)) {
|
||||
if (notification.getStatus().getFavourites_count() - 1 >= 0)
|
||||
notification.getStatus().setFavourites_count(notification.getStatus().getFavourites_count() - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ package fr.gouv.etalab.mastodon.drawers;
|
|||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Handler;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
|
@ -37,7 +36,6 @@ import android.support.v7.widget.PopupMenu;
|
|||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -83,7 +81,6 @@ import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
|||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
|
@ -681,7 +678,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
holder.status_reply.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CrossActions.doCrossReply(context, status, type);
|
||||
CrossActions.doCrossReply(context, status, type, false);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -815,20 +812,20 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
holder.status_favorite_count.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CrossActions.doCrossAction(context, status, (status.isFavourited()|| (status.getReblog() != null && status.getReblog().isFavourited()))? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this);
|
||||
CrossActions.doCrossAction(context, status, (status.isFavourited()|| (status.getReblog() != null && status.getReblog().isFavourited()))? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, false);
|
||||
}
|
||||
});
|
||||
|
||||
holder.status_reblog_count.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CrossActions.doCrossAction(context, status, (status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged()))? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this);
|
||||
CrossActions.doCrossAction(context, status, (status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged()))? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, false);
|
||||
}
|
||||
});
|
||||
holder.status_pin.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CrossActions.doCrossAction(context, status, (status.isPinned()|| (status.getReblog() != null && status.getReblog().isPinned()))? API.StatusAction.UNPIN:API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this);
|
||||
CrossActions.doCrossAction(context, status, (status.isPinned()|| (status.getReblog() != null && status.getReblog().isPinned()))? API.StatusAction.UNPIN:API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this, false);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ import mastodon.etalab.gouv.fr.mastodon.R;
|
|||
*/
|
||||
public class CrossActions {
|
||||
|
||||
public static void doCrossAction(final Context context, final Status status, final API.StatusAction doAction, final BaseAdapter baseAdapter, final OnPostActionInterface onPostActionInterface){
|
||||
List<Account> accounts = connectedAccounts(context, status);
|
||||
public static void doCrossAction(final Context context, final Status status, final API.StatusAction doAction, final BaseAdapter baseAdapter, final OnPostActionInterface onPostActionInterface, boolean limitedToOwner){
|
||||
List<Account> accounts = connectedAccounts(context, status, limitedToOwner);
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
|
||||
boolean undoAction = (doAction == API.StatusAction.UNPIN || doAction == API.StatusAction.UNREBLOG || doAction == API.StatusAction.UNFAVOURITE );
|
||||
|
@ -111,8 +111,8 @@ public class CrossActions {
|
|||
}
|
||||
}
|
||||
|
||||
public static void doCrossReply(final Context context, final Status status, final RetrieveFeedsAsyncTask.Type type){
|
||||
List<Account> accounts = connectedAccounts(context, status);
|
||||
public static void doCrossReply(final Context context, final Status status, final RetrieveFeedsAsyncTask.Type type, boolean limitedToOwner){
|
||||
List<Account> accounts = connectedAccounts(context, status, limitedToOwner);
|
||||
|
||||
if( accounts.size() == 1) {
|
||||
Intent intent = new Intent(context, TootActivity.class);
|
||||
|
@ -283,14 +283,14 @@ public class CrossActions {
|
|||
* @param context Context
|
||||
* @return List<Account>
|
||||
*/
|
||||
private static List<Account> connectedAccounts(Context context, Status status){
|
||||
private static List<Account> connectedAccounts(Context context, Status status, boolean limitedToOwner){
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<Account> accountstmp = new AccountDAO(context, db).getAllAccount();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
Account currentAccount = new AccountDAO(context, db).getAccountByID(userId);
|
||||
List<Account> accounts = new ArrayList<>();
|
||||
if( sharedpreferences.getBoolean(Helper.SET_ALLOW_CROSS_ACTIONS, true) && accountstmp.size() > 1 ){
|
||||
if( !limitedToOwner && sharedpreferences.getBoolean(Helper.SET_ALLOW_CROSS_ACTIONS, true) && accountstmp.size() > 1 ){
|
||||
//It's for a reply
|
||||
if( status != null){
|
||||
//Status is private or direct
|
||||
|
|
Loading…
Reference in New Issue