Merge branch 'develop' into improves_conversations

# Conflicts:
#	app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java
#	app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java
#	app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveContextInterface.java
This commit is contained in:
tom79 2017-10-21 14:41:12 +02:00
commit 7b92d0feff
3 changed files with 20 additions and 15 deletions

View File

@ -80,7 +80,6 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet
private boolean isRefreshed;
private ImageView pp_actionBar;
public static int position;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -225,7 +224,7 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet
}
@Override
public void onRetrieveContext(Context context, Error error) {
public void onRetrieveContext(Context context, Status statusFirst, Error error) {
swipeRefreshLayout.setRefreshing(false);
if( error != null){
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
@ -238,24 +237,32 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
position = 0;
boolean positionFound = false;
List<Status> statuses = new ArrayList<>();
if( statusFirst != null)
statuses.add(0, statusFirst);
if( context.getAncestors() != null && context.getAncestors().size() > 0){
for(Status status: context.getAncestors()){
statuses.add(status);
if( status.getId().equals(initialStatus.getId()))
positionFound =true;
if( !positionFound)
position++;
if( status.getId().equals(initialStatus.getId()))
positionFound = true;
}
}else if( statusFirst == null){
statuses.add(0, initialStatus);
positionFound = true;
}
if( context.getDescendants() != null && context.getDescendants().size() > 0){
for(Status status: context.getDescendants()){
statuses.add(status);
if( status.getId().equals(initialStatus.getId()))
positionFound =true;
if( !positionFound)
position++;
if( status.getId().equals(initialStatus.getId()))
positionFound = true;
}
}
RelativeLayout loader = findViewById(R.id.loader);

View File

@ -16,10 +16,8 @@ package fr.gouv.etalab.mastodon.asynctasks;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveContextInterface;
@ -32,6 +30,7 @@ public class RetrieveContextAsyncTask extends AsyncTask<Void, Void, Void> {
private Context context;
private String statusId;
private fr.gouv.etalab.mastodon.client.Entities.Status statusFirst;
private fr.gouv.etalab.mastodon.client.Entities.Context statusContext;
private OnRetrieveContextInterface listener;
private API api;
@ -45,20 +44,18 @@ public class RetrieveContextAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
api = new API(context);
Log.v(Helper.TAG,"statusId: " + statusId);
statusContext = api.getStatusContext(statusId);
Log.v(Helper.TAG,"statusContext: " + statusContext.getAncestors());
//Retrieves the first toot
/*if( statusContext.getAncestors().size() > 0 ) {
Log.v(Helper.TAG,"search for: " + statusContext.getAncestors().get(0).getId());
if( statusContext.getAncestors().size() > 0 ) {
statusFirst = statusContext.getAncestors().get(0);
statusContext = api.getStatusContext(statusContext.getAncestors().get(0).getId());
}*/
}
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveContext(statusContext, api.getError());
listener.onRetrieveContext(statusContext, statusFirst, api.getError());
}
}

View File

@ -17,11 +17,12 @@ package fr.gouv.etalab.mastodon.interfaces;
import fr.gouv.etalab.mastodon.client.Entities.Context;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Status;
/**
* Created by Thomas on 04/05/2017.
* Interface when a context for a status has been retrieved
*/
public interface OnRetrieveContextInterface {
void onRetrieveContext(Context context, Error error);
void onRetrieveContext(Context context, Status statusFirst, Error error);
}