6.6.2 - Alpha4 - 优化 binding 对象的生命周期管理方式

This commit is contained in:
SuperMonster003
2025-03-13 01:28:50 +08:00
parent 96991b3e95
commit b87cc53e92
19 changed files with 153 additions and 170 deletions

View File

@@ -3,6 +3,11 @@
<option name="RIGHT_MARGIN" value="1000" /> <option name="RIGHT_MARGIN" value="1000" />
<AndroidXmlCodeStyleSettings> <AndroidXmlCodeStyleSettings>
<option name="USE_CUSTOM_SETTINGS" value="true" /> <option name="USE_CUSTOM_SETTINGS" value="true" />
<option name="LAYOUT_SETTINGS">
<value>
<option name="INSERT_LINE_BREAK_BEFORE_NAMESPACE_DECLARATION" value="true" />
</value>
</option>
<option name="MANIFEST_SETTINGS"> <option name="MANIFEST_SETTINGS">
<value> <value>
<option name="INSERT_LINE_BREAK_BEFORE_NAMESPACE_DECLARATION" value="true" /> <option name="INSERT_LINE_BREAK_BEFORE_NAMESPACE_DECLARATION" value="true" />

View File

@@ -29,7 +29,7 @@ class ColorSelectActivity : BaseActivity() {
override val handleStatusBarThemeColorAutomatically = false override val handleStatusBarThemeColorAutomatically = false
private var binding: MtActivityColorSelectBinding? = null private lateinit var binding: MtActivityColorSelectBinding
private lateinit var mAppBarLayout: AppBarLayout private lateinit var mAppBarLayout: AppBarLayout
private lateinit var mTitle: String private lateinit var mTitle: String
@@ -48,17 +48,13 @@ class ColorSelectActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
handleIntent() handleIntent()
binding = MtActivityColorSelectBinding.inflate(layoutInflater).also { MtActivityColorSelectBinding.inflate(layoutInflater).also {
binding = it
setUpUI(it) setUpUI(it)
ViewUtils.excludePaddingClippableViewFromNavigationBar(it.colorSettingRecyclerView) ViewUtils.excludePaddingClippableViewFromNavigationBar(it.colorSettingRecyclerView)
} }
} }
override fun onDestroy() {
super.onDestroy()
binding = null
}
private fun handleIntent() { private fun handleIntent() {
mTitle = intent.getStringExtra("title") ?: getString(R.string.mt_color_picker_title) mTitle = intent.getStringExtra("title") ?: getString(R.string.mt_color_picker_title)
} }
@@ -104,7 +100,7 @@ class ColorSelectActivity : BaseActivity() {
} }
private fun setUpToolbarColors() { private fun setUpToolbarColors() {
val toolbar = binding!!.toolbar val toolbar = binding.toolbar
val aimColor = when { val aimColor = when {
ColorUtils.isLuminanceLight(mCurrentColor) -> getColor(R.color.day) ColorUtils.isLuminanceLight(mCurrentColor) -> getColor(R.color.day)
else -> getColor(R.color.night) else -> getColor(R.color.night)
@@ -121,7 +117,7 @@ class ColorSelectActivity : BaseActivity() {
} }
private fun setColorWithAnimation(view: View, colorTo: Int) { private fun setColorWithAnimation(view: View, colorTo: Int) {
binding!!.appBarContainer.setBackgroundColor(mCurrentColor) binding.appBarContainer.setBackgroundColor(mCurrentColor)
view.setBackgroundColor(colorTo) view.setBackgroundColor(colorTo)
mCurrentColor = colorTo mCurrentColor = colorTo

View File

@@ -9,6 +9,7 @@ import android.webkit.WebView
import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
import org.autojs.autojs.event.BackPressedHandler import org.autojs.autojs.event.BackPressedHandler
import org.autojs.autojs.ui.fragment.BindingDelegates.viewBinding
import org.autojs.autojs.ui.main.MainActivity import org.autojs.autojs.ui.main.MainActivity
import org.autojs.autojs.ui.main.QueryEvent import org.autojs.autojs.ui.main.QueryEvent
import org.autojs.autojs.ui.main.ViewPagerFragment import org.autojs.autojs.ui.main.ViewPagerFragment
@@ -27,7 +28,7 @@ import org.greenrobot.eventbus.Subscribe
*/ */
open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressedHandler, ViewStatesManageable { open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressedHandler, ViewStatesManageable {
private var binding: FragmentOnlineDocsBinding? = null private val binding by viewBinding(FragmentOnlineDocsBinding::bind)
private var mIndexUrl: String? = null private var mIndexUrl: String? = null
private var mPreviousQuery: String? = null private var mPreviousQuery: String? = null
@@ -45,12 +46,12 @@ open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressed
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return FragmentOnlineDocsBinding.inflate(inflater, container, false).also { binding = it }.root return FragmentOnlineDocsBinding.inflate(inflater, container, false).root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
binding!!.ewebView.also { ewebView -> binding.ewebView.also { ewebView ->
ewebView.webView.also { webView -> ewebView.webView.also { webView ->
mWebView = webView mWebView = webView
WebViewUtils.adaptDarkMode(requireContext(), webView) WebViewUtils.adaptDarkMode(requireContext(), webView)
@@ -107,11 +108,6 @@ open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressed
EventBus.getDefault().unregister(this) EventBus.getDefault().unregister(this)
} }
override fun onDestroyView() {
super.onDestroyView()
binding = null
}
override fun onPageShow() { override fun onPageShow() {
super.onPageShow() super.onPageShow()
mIsCurrentPageDocs = true mIsCurrentPageDocs = true

View File

@@ -253,7 +253,7 @@ class EditorView : LinearLayout, OnHintClickListener, ClickCallback, ToolbarFrag
private fun setMenuItemStatus(id: Int, enabled: Boolean) { private fun setMenuItemStatus(id: Int, enabled: Boolean) {
mMenuItemStatus.put(id, enabled) mMenuItemStatus.put(id, enabled)
val supportManager = activity.supportFragmentManager val supportManager = activity.supportFragmentManager
val fragment = supportManager.findFragmentById(R.id.toolbar_menu) as ToolbarFragment? val fragment = supportManager.findFragmentById(R.id.toolbar_menu) as ToolbarFragment<*>?
if (fragment == null) { if (fragment == null) {
mNormalToolbar.setMenuItemStatus(id, enabled) mNormalToolbar.setMenuItemStatus(id, enabled)
} else { } else {

View File

@@ -8,11 +8,9 @@ import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import org.autojs.autojs.execution.ScriptExecution; import org.autojs.autojs.execution.ScriptExecution;
import org.autojs.autojs.pio.PFiles; import org.autojs.autojs.pio.PFiles;
import org.autojs.autojs.rhino.debug.DebugCallback; import org.autojs.autojs.rhino.debug.DebugCallback;
@@ -46,7 +44,7 @@ import java.util.List;
// # at org.mozilla.javascript.Kit.codeBug(Kit.java:353) // # at org.mozilla.javascript.Kit.codeBug(Kit.java:353)
// # at org.autojs.autojs.rhino.debug.Dim.interrupted(Dim.java:806) // # at org.autojs.autojs.rhino.debug.Dim.interrupted(Dim.java:806)
// # ... ... // # ... ...
public class DebugToolbarFragment extends ToolbarFragment implements DebugCallback, CodeEditor.CursorChangeCallback, CodeEvaluator { public class DebugToolbarFragment extends ToolbarFragment<FragmentDebugToolbarBinding> implements DebugCallback, CodeEditor.CursorChangeCallback, CodeEvaluator {
private static final String LOG_TAG = "DebugToolbarFragment"; private static final String LOG_TAG = "DebugToolbarFragment";
private EditorView mEditorView; private EditorView mEditorView;
@@ -76,7 +74,6 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
mDebugger.clearAllBreakpoints(); mDebugger.clearAllBreakpoints();
} }
}; };
private FragmentDebugToolbarBinding binding;
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -84,11 +81,9 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
mHandler = new Handler(Looper.getMainLooper()); mHandler = new Handler(Looper.getMainLooper());
} }
@Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { protected FragmentDebugToolbarBinding createBinding(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container) {
binding = FragmentDebugToolbarBinding.inflate(inflater, container, false); return FragmentDebugToolbarBinding.inflate(inflater, container, false);
return binding.getRoot();
} }
@Override @Override
@@ -121,12 +116,6 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
binding.resume.setOnClickListener(v -> resume()); binding.resume.setOnClickListener(v -> resume());
} }
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
}
private void setupEditor() { private void setupEditor() {
CodeEditor editor = mEditorView.editor; CodeEditor editor = mEditorView.editor;
editor.setRedoUndoEnabled(false); editor.setRedoUndoEnabled(false);

View File

@@ -1,28 +1,21 @@
package org.autojs.autojs.ui.edit.toolbar; package org.autojs.autojs.ui.edit.toolbar;
import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.autojs.autojs6.R; import org.autojs.autojs6.R;
import org.autojs.autojs6.databinding.FragmentNormalToolbarBinding; import org.autojs.autojs6.databinding.FragmentNormalToolbarBinding;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class NormalToolbarFragment extends ToolbarFragment { public class NormalToolbarFragment extends ToolbarFragment<FragmentNormalToolbarBinding> {
private FragmentNormalToolbarBinding binding;
@Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { protected FragmentNormalToolbarBinding createBinding(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container) {
binding = FragmentNormalToolbarBinding.inflate(inflater, container, false); return FragmentNormalToolbarBinding.inflate(inflater, container, false);
return binding.getRoot();
} }
@Override @Override
@@ -30,9 +23,4 @@ public class NormalToolbarFragment extends ToolbarFragment {
return Arrays.asList(R.id.run, R.id.undo, R.id.redo, R.id.save); return Arrays.asList(R.id.run, R.id.undo, R.id.redo, R.id.save);
} }
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
}
} }

View File

@@ -4,27 +4,22 @@ import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.autojs.autojs6.R; import org.autojs.autojs6.R;
import org.autojs.autojs6.databinding.FragmentSearchToolbarBinding; import org.autojs.autojs6.databinding.FragmentSearchToolbarBinding;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class SearchToolbarFragment extends ToolbarFragment { public class SearchToolbarFragment extends ToolbarFragment<FragmentSearchToolbarBinding> {
public static final String ARGUMENT_SHOW_REPLACE_ITEM = "show_replace_item"; public static final String ARGUMENT_SHOW_REPLACE_ITEM = "show_replace_item";
private FragmentSearchToolbarBinding binding;
@Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { protected FragmentSearchToolbarBinding createBinding(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container) {
binding = FragmentSearchToolbarBinding.inflate(inflater, container, false); return FragmentSearchToolbarBinding.inflate(inflater, container, false);
return binding.getRoot();
} }
@Override @Override
@@ -42,9 +37,4 @@ public class SearchToolbarFragment extends ToolbarFragment {
return Arrays.asList(R.id.replace, R.id.find_next, R.id.find_prev, R.id.cancel_search); return Arrays.asList(R.id.replace, R.id.find_next, R.id.find_prev, R.id.cancel_search);
} }
@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
}
} }

View File

@@ -1,19 +1,17 @@
package org.autojs.autojs.ui.edit.toolbar; package org.autojs.autojs.ui.edit.toolbar;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.viewbinding.ViewBinding;
import android.view.View;
import org.autojs.autojs.ui.edit.EditorView; import org.autojs.autojs.ui.edit.EditorView;
import org.autojs.autojs.ui.fragment.BaseViewBindingFragment;
import org.autojs.autojs6.R; import org.autojs.autojs6.R;
import java.util.List; import java.util.List;
public abstract class ToolbarFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener { public abstract class ToolbarFragment<T extends ViewBinding> extends BaseViewBindingFragment<T> implements View.OnClickListener, View.OnLongClickListener {
public interface OnMenuItemClickListener { public interface OnMenuItemClickListener {
void onToolbarMenuItemClick(int id); void onToolbarMenuItemClick(int id);
@@ -79,7 +77,7 @@ public abstract class ToolbarFragment extends Fragment implements View.OnClickLi
@Override @Override
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
return mOnMenuItemLongClickListener != null && return mOnMenuItemLongClickListener != null &&
mOnMenuItemLongClickListener.onToolbarMenuItemLongClick(v.getId()); mOnMenuItemLongClickListener.onToolbarMenuItemLongClick(v.getId());
} }
public void setMenuItemStatus(int id, boolean enabled) { public void setMenuItemStatus(int id, boolean enabled) {

View File

@@ -8,7 +8,6 @@ import android.view.LayoutInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView
import android.widget.PopupMenu import android.widget.PopupMenu
import android.widget.TextView import android.widget.TextView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@@ -823,26 +822,20 @@ open class ExplorerView : ThemeColorSwipeRefreshLayout, SwipeRefreshLayout.OnRef
} }
internal inner class ExplorerPageViewHolder(itemView: View) : BindableViewHolder<Any>(itemView) { internal inner class ExplorerPageViewHolder(itemView: View) : BindableViewHolder<Any>(itemView) {
var mName: TextView
var mDirDate: TextView private val binding = ExplorerDirectoryBinding.bind(itemView).also {
var mOptions: View it.item.setOnClickListener { withItemSelected { onItemClick() } }
var mIcon: ImageView }
private var mName = binding.name
private var mDirDate = binding.scriptDirDate
private var mIcon = binding.icon
private var mOptions = binding.more.also {
it.setOnClickListener { withItemSelected { showOptionsMenu() } }
}
private var mExplorerPage: ExplorerPage? = null private var mExplorerPage: ExplorerPage? = null
init {
val binding = ExplorerDirectoryBinding.bind(itemView)
mName = binding.name
mDirDate = binding.scriptDirDate
mIcon = binding.icon
mOptions = binding.more
mOptions.setOnClickListener { withItemSelected { showOptionsMenu() } }
binding.item.setOnClickListener { withItemSelected { onItemClick() } }
}
override fun bind(data: Any, position: Int) { override fun bind(data: Any, position: Int) {
if (data !is ExplorerPage) return if (data !is ExplorerPage) return
mName.text = ExplorerViewHelper.getDisplayName(context, data) mName.text = ExplorerViewHelper.getDisplayName(context, data)
@@ -903,7 +896,8 @@ open class ExplorerView : ThemeColorSwipeRefreshLayout, SwipeRefreshLayout.OnRef
} }
internal inner class ExplorerCategoryViewHolder(itemView: View) : BindableViewHolder<Any>(itemView) { internal inner class ExplorerCategoryViewHolder(itemView: View) : BindableViewHolder<Any>(itemView) {
val binding: ExplorerCategoryBinding = ExplorerCategoryBinding.bind(itemView)
private val binding = ExplorerCategoryBinding.bind(itemView)
private var mIsDir = false private var mIsDir = false

View File

@@ -0,0 +1,28 @@
package org.autojs.autojs.ui.fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
public abstract class BaseViewBindingFragment<T extends androidx.viewbinding.ViewBinding> extends Fragment {
protected T binding;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = createBinding(inflater, container);
return getRootView(binding);
}
protected abstract T createBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup container);
protected View getRootView(@NonNull T binding) {
return binding.getRoot();
}
}

View File

@@ -0,0 +1,22 @@
package org.autojs.autojs.ui.fragment
import androidx.fragment.app.Fragment
import android.view.View
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
object BindingDelegates {
fun <T> Fragment.viewBinding(bindView: (View) -> T) = object : ReadOnlyProperty<Fragment, T> {
private var binding: T? = null
override fun getValue(thisRef: Fragment, property: KProperty<*>): T {
return binding ?: bindView(thisRef.requireView()).also { binding = it }
}
override fun toString() = "Binding for ${this@viewBinding.javaClass.name}: $binding"
}
}

View File

@@ -361,6 +361,7 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
return return
} }
if (!mBackPressObserver.onBackPressed(this)) { if (!mBackPressObserver.onBackPressed(this)) {
@Suppress("DEPRECATION")
super.onBackPressed() super.onBackPressed()
} }
} }

View File

@@ -14,6 +14,7 @@ import org.autojs.autojs.app.tool.FloatingButtonTool
import org.autojs.autojs.app.tool.JsonSocketClientTool import org.autojs.autojs.app.tool.JsonSocketClientTool
import org.autojs.autojs.app.tool.JsonSocketServerTool import org.autojs.autojs.app.tool.JsonSocketServerTool
import org.autojs.autojs.core.accessibility.AccessibilityTool import org.autojs.autojs.core.accessibility.AccessibilityTool
import org.autojs.autojs.core.pref.Pref
import org.autojs.autojs.permission.DisplayOverOtherAppsPermission import org.autojs.autojs.permission.DisplayOverOtherAppsPermission
import org.autojs.autojs.permission.IgnoreBatteryOptimizationsPermission import org.autojs.autojs.permission.IgnoreBatteryOptimizationsPermission
import org.autojs.autojs.permission.MediaProjectionPermission import org.autojs.autojs.permission.MediaProjectionPermission
@@ -25,13 +26,13 @@ import org.autojs.autojs.permission.WriteSystemSettingsPermission
import org.autojs.autojs.pluginclient.DevPluginService import org.autojs.autojs.pluginclient.DevPluginService
import org.autojs.autojs.pluginclient.JsonSocketClient import org.autojs.autojs.pluginclient.JsonSocketClient
import org.autojs.autojs.pluginclient.JsonSocketServer import org.autojs.autojs.pluginclient.JsonSocketServer
import org.autojs.autojs.core.pref.Pref
import org.autojs.autojs.service.AccessibilityService import org.autojs.autojs.service.AccessibilityService
import org.autojs.autojs.service.ForegroundService import org.autojs.autojs.service.ForegroundService
import org.autojs.autojs.service.NotificationService import org.autojs.autojs.service.NotificationService
import org.autojs.autojs.theme.app.ColorSelectActivity import org.autojs.autojs.theme.app.ColorSelectActivity
import org.autojs.autojs.ui.floating.CircularMenu import org.autojs.autojs.ui.floating.CircularMenu
import org.autojs.autojs.ui.floating.FloatyWindowManger import org.autojs.autojs.ui.floating.FloatyWindowManger
import org.autojs.autojs.ui.fragment.BindingDelegates.viewBinding
import org.autojs.autojs.ui.main.MainActivity import org.autojs.autojs.ui.main.MainActivity
import org.autojs.autojs.ui.settings.AboutActivity import org.autojs.autojs.ui.settings.AboutActivity
import org.autojs.autojs.ui.settings.PreferencesActivity import org.autojs.autojs.ui.settings.PreferencesActivity
@@ -52,7 +53,7 @@ import java.lang.ref.WeakReference
*/ */
open class DrawerFragment : Fragment() { open class DrawerFragment : Fragment() {
private var binding: FragmentDrawerBinding? = null private val binding by viewBinding(FragmentDrawerBinding::bind)
private var privateDrawerMenu: RecyclerView? = null private var privateDrawerMenu: RecyclerView? = null
private var privateContext: WeakReference<Context?>? = null private var privateContext: WeakReference<Context?>? = null
@@ -373,26 +374,26 @@ open class DrawerFragment : Fragment() {
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return FragmentDrawerBinding.inflate(inflater, container, false).also { binding = it }.root return FragmentDrawerBinding.inflate(inflater, container, false).root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
mDrawerMenu = binding!!.drawerMenu mDrawerMenu = binding.drawerMenu
initMenuItems() initMenuItems()
initMenuItemStates() initMenuItemStates()
setupListeners() setupListeners()
} }
private fun setupListeners() { private fun setupListeners() {
binding!!.settings.setOnClickListener { view -> binding.settings.setOnClickListener { view ->
startActivity( startActivity(
Intent(view.context, PreferencesActivity::class.java) Intent(view.context, PreferencesActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
) )
} }
binding!!.restart.setOnClickListener { mActivity.rebirth() } binding.restart.setOnClickListener { mActivity.rebirth() }
binding!!.exit.setOnClickListener { mActivity.exitCompletely() } binding.exit.setOnClickListener { mActivity.exitCompletely() }
} }
override fun onResume() { override fun onResume() {
@@ -410,7 +411,6 @@ open class DrawerFragment : Fragment() {
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
binding = null
privateDrawerMenu = null privateDrawerMenu = null
privateContext = null privateContext = null
privateActivity = null privateActivity = null

View File

@@ -21,6 +21,7 @@ import org.autojs.autojs.model.script.Scripts
import org.autojs.autojs.tool.SimpleObserver import org.autojs.autojs.tool.SimpleObserver
import org.autojs.autojs.ui.common.ScriptOperations import org.autojs.autojs.ui.common.ScriptOperations
import org.autojs.autojs.ui.explorer.ExplorerView import org.autojs.autojs.ui.explorer.ExplorerView
import org.autojs.autojs.ui.fragment.BindingDelegates.viewBinding
import org.autojs.autojs.ui.main.FloatingActionMenu import org.autojs.autojs.ui.main.FloatingActionMenu
import org.autojs.autojs.ui.main.FloatingActionMenu.OnFloatingActionButtonClickListener import org.autojs.autojs.ui.main.FloatingActionMenu.OnFloatingActionButtonClickListener
import org.autojs.autojs.ui.main.MainActivity import org.autojs.autojs.ui.main.MainActivity
@@ -44,7 +45,7 @@ import org.greenrobot.eventbus.Subscribe
open class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickListener, ViewStatesManageable { open class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickListener, ViewStatesManageable {
private var mBottomInset: Int = 0 private var mBottomInset: Int = 0
private var binding: FragmentExplorerBinding? = null private val binding by viewBinding(FragmentExplorerBinding::bind)
private var mExplorerView: ExplorerView? = null private var mExplorerView: ExplorerView? = null
private var mFloatingActionMenu: FloatingActionMenu? = null private var mFloatingActionMenu: FloatingActionMenu? = null
@@ -56,7 +57,7 @@ open class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickL
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return FragmentExplorerBinding.inflate(inflater, container, false).also { binding = it }.root return FragmentExplorerBinding.inflate(inflater, container, false).root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@@ -65,7 +66,7 @@ open class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickL
mBottomInset = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom mBottomInset = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom
insets insets
} }
mExplorerView = binding!!.itemList.also { explorerView -> mExplorerView = binding.itemList.also { explorerView ->
explorerView.setOnItemClickListener(object : ExplorerView.OnItemClickListener { explorerView.setOnItemClickListener(object : ExplorerView.OnItemClickListener {
override fun onItemClick(view: View?, item: ExplorerItem) { override fun onItemClick(view: View?, item: ExplorerItem) {
when { when {
@@ -190,7 +191,6 @@ open class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickL
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
binding = null
mExplorerView = null mExplorerView = null
mFloatingActionMenu = null mFloatingActionMenu = null
} }

View File

@@ -8,6 +8,7 @@ import android.view.ViewGroup
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.floatingactionbutton.FloatingActionButton
import org.autojs.autojs.AutoJs import org.autojs.autojs.AutoJs
import org.autojs.autojs.ui.fragment.BindingDelegates.viewBinding
import org.autojs.autojs.ui.main.ViewPagerFragment import org.autojs.autojs.ui.main.ViewPagerFragment
import org.autojs.autojs.ui.main.ViewStatesManageable import org.autojs.autojs.ui.main.ViewStatesManageable
import org.autojs.autojs.ui.widget.SimpleAdapterDataObserver import org.autojs.autojs.ui.widget.SimpleAdapterDataObserver
@@ -21,7 +22,7 @@ import org.autojs.autojs6.databinding.FragmentTaskManagerBinding
*/ */
open class TaskManagerFragment : ViewPagerFragment(45), ViewStatesManageable { open class TaskManagerFragment : ViewPagerFragment(45), ViewStatesManageable {
private var binding: FragmentTaskManagerBinding? = null private val binding by viewBinding(FragmentTaskManagerBinding::bind)
private var mTaskListRecyclerView: TaskListRecyclerView? = null private var mTaskListRecyclerView: TaskListRecyclerView? = null
private var mSwipeRefreshLayout: SwipeRefreshLayout? = null private var mSwipeRefreshLayout: SwipeRefreshLayout? = null
@@ -31,13 +32,13 @@ open class TaskManagerFragment : ViewPagerFragment(45), ViewStatesManageable {
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return FragmentTaskManagerBinding.inflate(inflater, container, false).also { binding = it }.root return FragmentTaskManagerBinding.inflate(inflater, container, false).root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
mSwipeRefreshLayout = binding!!.swipeRefreshLayout mSwipeRefreshLayout = binding.swipeRefreshLayout
mTaskListRecyclerView = binding!!.taskList.also { recyclerView -> mTaskListRecyclerView = binding.taskList.also { recyclerView ->
recyclerView.adapter?.registerAdapterDataObserver(object : SimpleAdapterDataObserver() { recyclerView.adapter?.registerAdapterDataObserver(object : SimpleAdapterDataObserver() {
override fun onSomethingChanged() { override fun onSomethingChanged() {
// To do something here maybe some day. // To do something here maybe some day.
@@ -75,7 +76,6 @@ open class TaskManagerFragment : ViewPagerFragment(45), ViewStatesManageable {
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
binding = null
mTaskListRecyclerView = null mTaskListRecyclerView = null
mSwipeRefreshLayout = null mSwipeRefreshLayout = null
} }

View File

@@ -17,11 +17,9 @@ import org.autojs.autojs6.databinding.SelectLauncherShortcutBinding
*/ */
class LauncherShortcutsPreference : MaterialPreference { class LauncherShortcutsPreference : MaterialPreference {
private var binding: SelectLauncherShortcutBinding? = null
private val mDialog by lazy { private val mDialog by lazy {
val binding = SelectLauncherShortcutBinding.inflate(LayoutInflater.from(prefContext)).also { binding = it } val binding = SelectLauncherShortcutBinding.inflate(LayoutInflater.from(prefContext))
MaterialDialog.Builder(prefContext) MaterialDialog.Builder(prefContext)
.customView(binding.root, true) .customView(binding.root, true)
@@ -79,11 +77,6 @@ class LauncherShortcutsPreference : MaterialPreference {
super.onClick() super.onClick()
} }
override fun onDetached() {
super.onDetached()
binding = null
}
private fun showShortcutsSelectionDialog() { private fun showShortcutsSelectionDialog() {
if (!mDialog.isShowing) mDialog.show() if (!mDialog.isShowing) mDialog.show()
} }

View File

@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.widget.LinearLayout
import org.autojs.autojs.ui.BaseActivity import org.autojs.autojs.ui.BaseActivity
import org.autojs.autojs.ui.floating.FloatyWindowManger import org.autojs.autojs.ui.floating.FloatyWindowManger
import org.autojs.autojs.ui.main.MainActivity import org.autojs.autojs.ui.main.MainActivity
@@ -20,8 +19,6 @@ class SplashActivity : BaseActivity() {
override val handleStatusBarThemeColorAutomatically = false override val handleStatusBarThemeColorAutomatically = false
private var binding: ActivitySplashBinding? = null
private var mAlreadyEnterNextActivity = false private var mAlreadyEnterNextActivity = false
private var mPaused = false private var mPaused = false
@@ -30,8 +27,7 @@ class SplashActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val binding = ActivitySplashBinding.inflate(layoutInflater).also { binding = it } setContentView(ActivitySplashBinding.inflate(layoutInflater).root)
setContentView(binding.root)
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
mHandler = Looper.myLooper()?.let { Handler(it) } ?: Handler() mHandler = Looper.myLooper()?.let { Handler(it) } ?: Handler()
@@ -53,11 +49,6 @@ class SplashActivity : BaseActivity() {
} }
} }
override fun onDestroy() {
super.onDestroy()
binding = null
}
private fun enterNextActivity() { private fun enterNextActivity() {
if (!mAlreadyEnterNextActivity && !mPaused) { if (!mAlreadyEnterNextActivity && !mPaused) {
mAlreadyEnterNextActivity = true mAlreadyEnterNextActivity = true
@@ -68,7 +59,7 @@ class SplashActivity : BaseActivity() {
companion object { companion object {
const val INIT_TIMEOUT: Long = 1000 const val INIT_TIMEOUT = 1000L
} }

View File

@@ -2,8 +2,8 @@ package org.autojs.autojs.ui.widget
import android.content.Context import android.content.Context
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.drawable.Drawable
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.ImageView import android.widget.ImageView
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
@@ -11,47 +11,50 @@ import androidx.core.content.ContextCompat
import org.autojs.autojs.theme.ThemeColorManager import org.autojs.autojs.theme.ThemeColorManager
import org.autojs.autojs.util.DrawableUtils import org.autojs.autojs.util.DrawableUtils
import org.autojs.autojs6.R import org.autojs.autojs6.R
import org.autojs.autojs6.databinding.ToolbarMenuItemBinding
/** /**
* Created by Stardust on Jan 29, 2017. * Created by Stardust on Jan 29, 2017.
*/ */
class ToolbarMenuItem : LinearLayout { class ToolbarMenuItem : LinearLayout {
private val mColorDisabled: Int private lateinit var mImageView: ImageView
get() = when (ThemeColorManager.isThemeColorLuminanceLight()) { private var mTextView: TextView
true -> ContextCompat.getColor(context, R.color.toolbar_menu_item_disabled_dark)
else -> ContextCompat.getColor(context, R.color.toolbar_menu_item_disabled_light) private val enabledDrawable by lazy {
} mImageView.drawable
private val mColorEnabled: Int }
private val disabledDrawable by lazy {
DrawableUtils.setDrawableColorFilterSrcIn(enabledDrawable, colorDisabled)
}
private val colorEnabled: Int
get() = when (ThemeColorManager.isThemeColorLuminanceLight()) { get() = when (ThemeColorManager.isThemeColorLuminanceLight()) {
true -> ContextCompat.getColor(context, R.color.toolbar_menu_item_enabled_dark) true -> ContextCompat.getColor(context, R.color.toolbar_menu_item_enabled_dark)
else -> ContextCompat.getColor(context, R.color.toolbar_menu_item_enabled_light) else -> ContextCompat.getColor(context, R.color.toolbar_menu_item_enabled_light)
} }
private var mImageView: ImageView private val colorDisabled: Int
private var mTextView: TextView get() = when (ThemeColorManager.isThemeColorLuminanceLight()) {
private var mEnabledDrawable: Drawable? = null true -> ContextCompat.getColor(context, R.color.toolbar_menu_item_disabled_dark)
private var mDisabledDrawable: Drawable? = null else -> ContextCompat.getColor(context, R.color.toolbar_menu_item_disabled_light)
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) { constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
inflate(context, R.layout.toolbar_menu_item, this) val binding = ToolbarMenuItemBinding.inflate(LayoutInflater.from(context), this, true)
val a = context.obtainStyledAttributes(attrs, R.styleable.ToolbarMenuItem) context.obtainStyledAttributes(attrs, R.styleable.ToolbarMenuItem).also { ta ->
mImageView = binding.icon.apply {
setImageResource(ta.getResourceId(R.styleable.ToolbarMenuItem_icon, 0))
imageTintList = ColorStateList.valueOf(colorEnabled)
}
mTextView = binding.text.apply {
text = ta.getString(R.styleable.ToolbarMenuItem_text)
setTextColor(colorEnabled)
}
}.recycle()
val iconText = a.getString(R.styleable.ToolbarMenuItem_text)
val iconResId = a.getResourceId(R.styleable.ToolbarMenuItem_icon, 0)
a.recycle()
mImageView = findViewById<ImageView?>(R.id.icon).apply {
setImageResource(iconResId)
imageTintList = ColorStateList.valueOf(mColorEnabled)
}
mTextView = findViewById<TextView?>(R.id.text).apply {
text = iconText
setTextColor(mColorEnabled)
}
} }
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : this(context, attrs, defStyleAttr, 0) constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : this(context, attrs, defStyleAttr, 0)
@@ -59,22 +62,11 @@ class ToolbarMenuItem : LinearLayout {
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
override fun setEnabled(enabled: Boolean) { override fun setEnabled(enabled: Boolean) {
if (enabled != isEnabled) { if (isEnabled == enabled) return
super.setEnabled(enabled) super.setEnabled(enabled)
ensureEnabledDrawable() mImageView.setImageDrawable(if (enabled) enabledDrawable else disabledDrawable)
ensureDisabledDrawable() mImageView.imageTintList = ColorStateList.valueOf(if (enabled) colorEnabled else colorDisabled)
mImageView.setImageDrawable(if (enabled) mEnabledDrawable else mDisabledDrawable) mTextView.setTextColor(if (enabled) colorEnabled else colorDisabled)
mImageView.imageTintList = ColorStateList.valueOf(if (enabled) mColorEnabled else mColorDisabled)
mTextView.setTextColor(if (enabled) mColorEnabled else mColorDisabled)
}
}
private fun ensureDisabledDrawable() {
mDisabledDrawable = mDisabledDrawable ?: DrawableUtils.setDrawableColorFilterSrcIn(mEnabledDrawable, mColorDisabled)
}
private fun ensureEnabledDrawable() {
mEnabledDrawable = mEnabledDrawable ?: mImageView.drawable
} }
} }

View File

@@ -1,5 +1,5 @@
#Wed Mar 12 14:53:38 CST 2025 #Thu Mar 13 01:24:48 CST 2025
BUILD_TIME=1741762418877 BUILD_TIME=1741800288640
COMPILE_SDK_VERSION=35 COMPILE_SDK_VERSION=35
JAVA_VERSION=23 JAVA_VERSION=23
JAVA_VERSION_MIN_RADICAL=0 JAVA_VERSION_MIN_RADICAL=0
@@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
TARGET_SDK_VERSION=35 TARGET_SDK_VERSION=35
TARGET_SDK_VERSION_INRT=29 TARGET_SDK_VERSION_INRT=29
VERSION_BUILD=3018 VERSION_BUILD=3022
VERSION_NAME=6.6.2 Alpha4 VERSION_NAME=6.6.2 Alpha4
VSCODE_EXT_REQUIRED_VERSION=1.0.8 VSCODE_EXT_REQUIRED_VERSION=1.0.8