fix current fragment detection

This commit is contained in:
sk 2023-06-01 19:12:50 +02:00
parent 798a43906f
commit 2c4504bad3
1 changed files with 12 additions and 7 deletions

View File

@ -8,6 +8,8 @@ import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import org.joinmastodon.android.api.ObjectValidationException; import org.joinmastodon.android.api.ObjectValidationException;
import org.joinmastodon.android.api.session.AccountSession; import org.joinmastodon.android.api.session.AccountSession;
@ -28,8 +30,6 @@ import androidx.annotation.Nullable;
import me.grishka.appkit.FragmentStackActivity; import me.grishka.appkit.FragmentStackActivity;
public class MainActivity extends FragmentStackActivity implements ProvidesAssistContent { public class MainActivity extends FragmentStackActivity implements ProvidesAssistContent {
private Fragment currentFragment;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState){ protected void onCreate(@Nullable Bundle savedInstanceState){
UiUtils.setUserPreferredTheme(this); UiUtils.setUserPreferredTheme(this);
@ -200,15 +200,20 @@ public class MainActivity extends FragmentStackActivity implements ProvidesAssis
} }
} }
@Override public Fragment getCurrentFragment() {
public void showFragment(Fragment fragment) { for (int i = fragmentContainers.size() - 1; i >= 0; i--) {
super.showFragment(fragment); FrameLayout fl = fragmentContainers.get(i);
this.currentFragment = fragment; if (fl.getVisibility() == View.VISIBLE) {
return getFragmentManager().findFragmentById(fl.getId());
}
}
return null;
} }
@Override @Override
public void onProvideAssistContent(AssistContent assistContent) { public void onProvideAssistContent(AssistContent assistContent) {
super.onProvideAssistContent(assistContent); super.onProvideAssistContent(assistContent);
callFragmentToProvideAssistContent(currentFragment, assistContent); Fragment fragment = getCurrentFragment();
if (fragment != null) callFragmentToProvideAssistContent(fragment, assistContent);
} }
} }