Update activity for lists
This commit is contained in:
parent
89da878b79
commit
88572430ae
|
@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.activities;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -27,6 +28,7 @@ import android.widget.Toast;
|
||||||
import fr.gouv.etalab.mastodon.R;
|
import fr.gouv.etalab.mastodon.R;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
|
import fr.gouv.etalab.mastodon.drawers.ListAdapter;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
|
||||||
setTitle(title);
|
setTitle(title);
|
||||||
loader.setVisibility(View.VISIBLE);
|
loader.setVisibility(View.VISIBLE);
|
||||||
lv_status.setVisibility(View.GONE);
|
lv_status.setVisibility(View.GONE);
|
||||||
|
new ManageListsAsyncTask(getApplicationContext(),listId, null ,null, ListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
public enum action{
|
public enum action{
|
||||||
GET_LIST,
|
GET_LIST,
|
||||||
|
GET_LIST_TIMELINE,
|
||||||
GET_LIST_ACCOUNT,
|
GET_LIST_ACCOUNT,
|
||||||
CREATE_LIST,
|
CREATE_LIST,
|
||||||
DELETE_LIST,
|
DELETE_LIST,
|
||||||
|
@ -52,7 +53,8 @@ public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
private String[] accountsId;
|
private String[] accountsId;
|
||||||
private action apiAction;
|
private action apiAction;
|
||||||
private WeakReference<Context> contextReference;
|
private WeakReference<Context> contextReference;
|
||||||
|
private String max_id, since_id;
|
||||||
|
private int limit;
|
||||||
|
|
||||||
public ManageListsAsyncTask(Context context, action apiAction, String[] accountsId, String targetedId, String listId, String title, OnListActionInterface onListActionInterface){
|
public ManageListsAsyncTask(Context context, action apiAction, String[] accountsId, String targetedId, String listId, String title, OnListActionInterface onListActionInterface){
|
||||||
contextReference = new WeakReference<>(context);
|
contextReference = new WeakReference<>(context);
|
||||||
|
@ -64,11 +66,22 @@ public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
this.targetedId = targetedId;
|
this.targetedId = targetedId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ManageListsAsyncTask(Context context, String listId, String max_id, String since_id, OnListActionInterface onListActionInterface){
|
||||||
|
contextReference = new WeakReference<>(context);
|
||||||
|
this.listener = onListActionInterface;
|
||||||
|
this.listId = listId;
|
||||||
|
this.max_id = max_id;
|
||||||
|
this.since_id = since_id;
|
||||||
|
this.limit = 40;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
Log.v(Helper.TAG,"apiAction: " + apiAction);
|
Log.v(Helper.TAG, "apiAction: " + apiAction);
|
||||||
if(apiAction == action.GET_LIST){
|
if (apiAction == action.GET_LIST) {
|
||||||
apiResponse = new API(contextReference.get()).getLists();
|
apiResponse = new API(contextReference.get()).getLists();
|
||||||
|
}else if(apiAction == action.GET_LIST_TIMELINE){
|
||||||
|
apiResponse = new API(contextReference.get()).getListTimeline(this.targetedId, this.max_id, this.since_id, this.limit);
|
||||||
}else if(apiAction == action.GET_LIST_ACCOUNT){
|
}else if(apiAction == action.GET_LIST_ACCOUNT){
|
||||||
apiResponse = new API(contextReference.get()).getLists(this.targetedId);
|
apiResponse = new API(contextReference.get()).getLists(this.targetedId);
|
||||||
}else if( apiAction == action.CREATE_LIST){
|
}else if( apiAction == action.CREATE_LIST){
|
||||||
|
|
|
@ -1186,6 +1186,40 @@ public class API {
|
||||||
return apiResponse;
|
return apiResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves list timeline *synchronously*
|
||||||
|
* @param list_id String id of the list
|
||||||
|
* @param max_id String id max
|
||||||
|
* @param since_id String since the id
|
||||||
|
* @param limit int limit - max value 40
|
||||||
|
* @return APIResponse
|
||||||
|
*/
|
||||||
|
public APIResponse getListTimeline(String list_id, String max_id, String since_id, int limit) {
|
||||||
|
|
||||||
|
HashMap<String, String> params = new HashMap<>();
|
||||||
|
if (max_id != null)
|
||||||
|
params.put("max_id", max_id);
|
||||||
|
if (since_id != null)
|
||||||
|
params.put("since_id", since_id);
|
||||||
|
if (0 > limit || limit > 80)
|
||||||
|
limit = 80;
|
||||||
|
params.put("limit",String.valueOf(limit));
|
||||||
|
statuses = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
HttpsConnection httpsConnection = new HttpsConnection();
|
||||||
|
String response = httpsConnection.get(getAbsoluteUrl(String.format("/timelines/list/%s",list_id)), 60, params, prefKeyOauthTokenT);
|
||||||
|
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||||
|
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||||
|
statuses = parseStatuses(new JSONArray(response));
|
||||||
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
|
setError(e.getStatusCode(), e);
|
||||||
|
}catch (Exception e) {
|
||||||
|
setDefaultError();
|
||||||
|
}
|
||||||
|
apiResponse.setStatuses(statuses);
|
||||||
|
return apiResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get accounts in a list for a user
|
* Get accounts in a list for a user
|
||||||
|
|
Loading…
Reference in New Issue