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