Update thread view after sent reply (closes #74)

This commit is contained in:
Raphael Michel 2017-04-15 19:44:29 +02:00
parent f4109f38a8
commit fce573f1ec
6 changed files with 60 additions and 4 deletions

View file

@ -101,6 +101,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
private static final int MEDIA_PICK_RESULT = 1;
private static final int PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
private static final int MEDIA_SIZE_UNKNOWN = -1;
private static final int COMPOSE_SUCCESS = -1;
private String inReplyToId;
private EditText textEditor;
@ -816,6 +817,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFrag
private void onSendSuccess() {
Snackbar bar = Snackbar.make(findViewById(R.id.activity_compose), getString(R.string.confirmation_send), Snackbar.LENGTH_SHORT);
bar.show();
setResult(COMPOSE_SUCCESS);
finish();
}

View file

@ -66,6 +66,7 @@ import retrofit2.Response;
public class MainActivity extends BaseActivity {
private static final String TAG = "MainActivity"; // logging tag and Volley request tag
protected static int COMPOSE_RESULT = 1;
private String loggedInAccountId;
private String loggedInAccountUsername;
@ -99,7 +100,7 @@ public class MainActivity extends BaseActivity {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), ComposeActivity.class);
startActivity(intent);
startActivityForResult(intent, COMPOSE_RESULT);
}
});
@ -474,6 +475,17 @@ public class MainActivity extends BaseActivity {
Log.e(TAG, "Failed to fetch user info. " + exception.getMessage());
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == COMPOSE_RESULT && resultCode == ComposeActivity.RESULT_OK) {
TimelinePagerAdapter adapter = (TimelinePagerAdapter) viewPager.getAdapter();
if (adapter.getCurrentFragment() instanceof SFragment) {
((SFragment) adapter.getCurrentFragment()).onSuccessfulStatus();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onBackPressed() {
if(drawer != null && drawer.isDrawerOpen()) {

View file

@ -44,9 +44,10 @@ import retrofit2.Callback;
* adapters. I feel like the profile pages and thread viewer, which I haven't made yet, will also
* overlap functionality. So, I'm momentarily leaving it and hopefully working on those will clear
* up what needs to be where. */
public class SFragment extends BaseFragment {
public abstract class SFragment extends BaseFragment {
protected String loggedInAccountId;
protected String loggedInUsername;
protected static int COMPOSE_RESULT = 1;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
@ -79,11 +80,23 @@ public class SFragment extends BaseFragment {
intent.putExtra("reply_visibility", replyVisibility);
intent.putExtra("content_warning", contentWarning);
intent.putExtra("mentioned_usernames", mentionedUsernames.toArray(new String[0]));
startActivity(intent);
startActivityForResult(intent, COMPOSE_RESULT);
}
public void onSuccessfulStatus() {
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == COMPOSE_RESULT && resultCode == ComposeActivity.RESULT_OK) {
onSuccessfulStatus();
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
protected void reblog(final Status status, final boolean reblog,
final RecyclerView.Adapter adapter, final int position) {
final RecyclerView.Adapter adapter, final int position) {
String id = status.getActionableId();
Callback<Status> cb = new Callback<Status>() {

View file

@ -299,6 +299,14 @@ public class TimelineFragment extends SFragment implements
}
}
@Override
public void onSuccessfulStatus() {
if (kind == Kind.HOME || kind == Kind.PUBLIC_FEDERATED || kind == Kind.PUBLIC_LOCAL) {
onRefresh();
}
super.onSuccessfulStatus();
}
public void onReply(int position) {
super.reply(adapter.getItem(position));
}

View file

@ -18,12 +18,27 @@ package com.keylesspalace.tusky;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;
class TimelinePagerAdapter extends FragmentPagerAdapter {
private Fragment currentFragment;
TimelinePagerAdapter(FragmentManager manager) {
super(manager);
}
public Fragment getCurrentFragment() {
return currentFragment;
}
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
if (getCurrentFragment() != object) {
currentFragment = ((Fragment) object);
}
super.setPrimaryItem(container, position, object);
}
@Override
public Fragment getItem(int i) {
switch (i) {

View file

@ -155,6 +155,12 @@ public class ViewThreadFragment extends SFragment implements
sendThreadRequest(thisThreadsStatusId);
}
@Override
public void onSuccessfulStatus() {
onRefresh();
super.onSuccessfulStatus();
}
public void onReply(int position) {
super.reply(adapter.getItem(position));
}