Some changes
This commit is contained in:
parent
b8a1a1fe8e
commit
db41068207
|
@ -17,7 +17,6 @@ package fr.gouv.etalab.mastodon.client;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.loopj.android.http.AsyncHttpResponseHandler;
|
||||
|
@ -1307,10 +1306,12 @@ public class API {
|
|||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||
setError(statusCode, error);
|
||||
error.printStackTrace();
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, String message, Throwable error){
|
||||
setError(statusCode, error);
|
||||
error.printStackTrace();
|
||||
}
|
||||
});
|
||||
return results;
|
||||
|
|
|
@ -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.getId(), 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);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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.getId(), 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);
|
||||
|
||||
}
|
||||
});
|
||||
|
|
|
@ -829,20 +829,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, targetedId, (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);
|
||||
}
|
||||
});
|
||||
|
||||
holder.status_reblog_count.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CrossActions.doCrossAction(context, status, targetedId, (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);
|
||||
}
|
||||
});
|
||||
holder.status_pin.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CrossActions.doCrossAction(context, status, targetedId, (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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -23,11 +23,9 @@ import android.os.AsyncTask;
|
|||
import android.os.Build;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
|
@ -43,8 +41,8 @@ import mastodon.etalab.gouv.fr.mastodon.R;
|
|||
*/
|
||||
public class CrossActions {
|
||||
|
||||
public static void doCrossAction(final Context context, final Status status, final String targetedId, final API.StatusAction doAction, final BaseAdapter baseAdapter, final OnPostActionInterface onPostActionInterface){
|
||||
List<Account> accounts = Helper.connectedAccounts(context);
|
||||
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);
|
||||
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 );
|
||||
|
@ -85,7 +83,7 @@ public class CrossActions {
|
|||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account loggedAccount = new AccountDAO(context, db).getAccountByID(userId);
|
||||
if(loggedAccount.getInstance().equals(selectedAccount.getInstance())){
|
||||
new PostActionAsyncTask(context, selectedAccount, doAction, targetedId, onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new PostActionAsyncTask(context, selectedAccount, doAction, status.getId(), onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}else{ //Account is from another instance
|
||||
new PostActionAsyncTask(context, selectedAccount, status, doAction, onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
@ -93,7 +91,7 @@ public class CrossActions {
|
|||
if (doAction == API.StatusAction.REBLOG) {
|
||||
status.setReblogged(true);
|
||||
} else if (doAction == API.StatusAction.FAVOURITE) {
|
||||
status.setReblogged(true);
|
||||
status.setFavourited(true);
|
||||
} else if (doAction == API.StatusAction.PIN) {
|
||||
status.setPinned(true);
|
||||
}
|
||||
|
@ -212,4 +210,25 @@ public class CrossActions {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the list of connected accounts when cross actions are allowed otherwise, returns the current account
|
||||
* @param context Context
|
||||
* @return List<Account>
|
||||
*/
|
||||
private static List<Account> connectedAccounts(Context context){
|
||||
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> accounts = new AccountDAO(context, db).getAllAccount();
|
||||
if( sharedpreferences.getBoolean(Helper.SET_ALLOW_CROSS_ACTIONS, true) && accounts.size() > 1 ){
|
||||
return accounts;
|
||||
}else {
|
||||
List<Account> oneAccount = new ArrayList<>();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
Account account = new AccountDAO(context, db).getAccountByID(userId);
|
||||
oneAccount.add(account);
|
||||
return oneAccount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1558,26 +1558,7 @@ public class Helper {
|
|||
tableLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of connected accounts when cross actions are allowed otherwise, returns the current account
|
||||
* @param context Context
|
||||
* @return List<Account>
|
||||
*/
|
||||
public static List<Account> connectedAccounts(Context context){
|
||||
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> accounts = new AccountDAO(context, db).getAllAccount();
|
||||
if( sharedpreferences.getBoolean(Helper.SET_ALLOW_CROSS_ACTIONS, true) && accounts.size() > 1 ){
|
||||
return accounts;
|
||||
}else {
|
||||
|
||||
List<Account> oneAccount = new ArrayList<>();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
Account account = new AccountDAO(context, db).getAccountByID(userId);
|
||||
oneAccount.add(account);
|
||||
return oneAccount;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a bitmap from a view
|
||||
|
|
Loading…
Reference in New Issue