diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java index 4210dd3c6..fd8e007b4 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java @@ -79,7 +79,7 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet private ListView lv_status; private boolean isRefreshed; private ImageView pp_actionBar; - + public static int position; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -224,7 +224,7 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet } @Override - public void onRetrieveFeeds(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); @@ -237,25 +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); - int position = 0; + position = 0; boolean positionFound = false; List 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); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java index ab56f0e04..a66a706a6 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java @@ -16,8 +16,11 @@ 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.client.Entities.Status; +import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveContextInterface; @@ -30,6 +33,7 @@ public class RetrieveContextAsyncTask extends AsyncTask { 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; @@ -46,6 +50,7 @@ public class RetrieveContextAsyncTask extends AsyncTask { statusContext = api.getStatusContext(statusId); //Retrieves the first toot if( statusContext.getAncestors().size() > 0 ) { + statusFirst = statusContext.getAncestors().get(0); statusContext = api.getStatusContext(statusContext.getAncestors().get(0).getId()); } return null; @@ -53,7 +58,7 @@ public class RetrieveContextAsyncTask extends AsyncTask { @Override protected void onPostExecute(Void result) { - listener.onRetrieveFeeds(statusContext, api.getError()); + listener.onRetrieveContext(statusContext, statusFirst, api.getError()); } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveContextInterface.java b/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveContextInterface.java index 909211fca..e1bdf4108 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveContextInterface.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveContextInterface.java @@ -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 onRetrieveFeeds(Context context, Error error); + void onRetrieveContext(Context context, Status statusFirst, Error error); }