diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 5be683a2f..cfd1eb6fe 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -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(); } diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index 434152697..8a2b7bc62 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -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()) { diff --git a/app/src/main/java/com/keylesspalace/tusky/SFragment.java b/app/src/main/java/com/keylesspalace/tusky/SFragment.java index f18f07f04..54d897a09 100644 --- a/app/src/main/java/com/keylesspalace/tusky/SFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/SFragment.java @@ -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 cb = new Callback() { diff --git a/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java b/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java index 4f1b6e205..825411e8b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java @@ -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)); } diff --git a/app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java b/app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java index af9bc6393..2e81adc33 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java @@ -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) { diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java index 67952669b..39baf8ee6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/ViewThreadFragment.java @@ -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)); }