给fragment添加tag

This commit is contained in:
itgaojian163 2022-07-01 23:37:15 +08:00
parent 179b6e402e
commit b857e3c4e2
7 changed files with 17 additions and 48 deletions

2
.gitignore vendored
View File

@ -1,6 +1,6 @@
*.iml *.iml
.gradle .gradle
/.idea .idea/
/local.properties /local.properties
/.idea/caches /.idea/caches
/.idea/libraries /.idea/libraries

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="delegatedBuild" value="true" />
<option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="11" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/agentwebnodule" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/baselib" />
<option value="$PROJECT_DIR$/lfilepickerlibrary" />
<option value="$PROJECT_DIR$/mainmodule" />
<option value="$PROJECT_DIR$/moduleijkplayer" />
<option value="$PROJECT_DIR$/oamodule" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
</project>

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@ -24,7 +24,6 @@ import com.hjq.toast.ToastUtils;
import com.jcodecraeer.xrecyclerview.progressindicator.AVLoadingIndicatorView; import com.jcodecraeer.xrecyclerview.progressindicator.AVLoadingIndicatorView;
import com.scwang.smart.refresh.layout.SmartRefreshLayout; import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.tenlionsoft.baselib.R; import com.tenlionsoft.baselib.R;
import com.tenlionsoft.baselib.utils.LogUtils;
import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts; import androidx.activity.result.contract.ActivityResultContracts;
@ -55,6 +54,7 @@ public abstract class BaseFragment extends Fragment {
protected TextView mTvFragmentOption; protected TextView mTvFragmentOption;
protected TextView mTvFragmentTitle; protected TextView mTvFragmentTitle;
private ActivityResultLauncher<Intent> mLauncher; private ActivityResultLauncher<Intent> mLauncher;
private String tag;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -88,6 +88,7 @@ public abstract class BaseFragment extends Fragment {
setDataToView(mDataView); setDataToView(mDataView);
return contentView; return contentView;
} }
/** /**
* 将view的点击区域放大 * 将view的点击区域放大
* *
@ -107,6 +108,7 @@ public abstract class BaseFragment extends Fragment {
parentView.setTouchDelegate(touchDelegate); parentView.setTouchDelegate(touchDelegate);
}); });
} }
/** /**
* 设置是否显示titlebar * 设置是否显示titlebar
*/ */
@ -238,6 +240,7 @@ public abstract class BaseFragment extends Fragment {
break; break;
} }
} }
public void showSoftKeyboard(EditText editText) { public void showSoftKeyboard(EditText editText) {
if (editText != null) { if (editText != null) {
editText.setFocusable(true); editText.setFocusable(true);
@ -250,6 +253,7 @@ public abstract class BaseFragment extends Fragment {
inputManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); inputManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
} }
} }
public Context getApplicationContext() { public Context getApplicationContext() {
return context; return context;
} }
@ -270,6 +274,14 @@ public abstract class BaseFragment extends Fragment {
setContentView((ViewGroup) inflater.inflate(layoutResID, container, false)); setContentView((ViewGroup) inflater.inflate(layoutResID, container, false));
} }
public String getCustomTag() {
return tag;
}
public void setCustomTag(String tag) {
this.tag = tag;
}
public void setContentView(View view) { public void setContentView(View view) {
contentView = view; contentView = view;
} }

View File

@ -40,6 +40,7 @@ public class FragmentUtils {
public static BaseFragment getFragment(String path, String tag) { public static BaseFragment getFragment(String path, String tag) {
BaseFragment fragment = (BaseFragment) ARouter.getInstance().build(path).setTag(tag).navigation(); BaseFragment fragment = (BaseFragment) ARouter.getInstance().build(path).setTag(tag).navigation();
fragment.setCustomTag(tag);
return fragment; return fragment;
} }

View File

@ -206,8 +206,8 @@ public class UserRecordDetailActivity extends BaseActivity {
private void chooseFragment(String type) { private void chooseFragment(String type) {
for (int i = 0; i < mFragments.size(); i++) { for (int i = 0; i < mFragments.size(); i++) {
BaseFragment fragment = mFragments.get(i); BaseFragment fragment = mFragments.get(i);
LogUtils.e(fragment.getTag()); LogUtils.e(fragment.getCustomTag());
if (type.equals(fragment.getTag())) { if (type.equals(fragment.getCustomTag())) {
mVpContent.setCurrentItem(i, false); mVpContent.setCurrentItem(i, false);
break; break;
} }