6.6.2 - Alpha4 - 优化 binding 对象的生命周期管理方式
This commit is contained in:
@@ -29,7 +29,7 @@ class ColorSelectActivity : BaseActivity() {
|
||||
|
||||
override val handleStatusBarThemeColorAutomatically = false
|
||||
|
||||
private var binding: MtActivityColorSelectBinding? = null
|
||||
private lateinit var binding: MtActivityColorSelectBinding
|
||||
|
||||
private lateinit var mAppBarLayout: AppBarLayout
|
||||
private lateinit var mTitle: String
|
||||
@@ -48,17 +48,13 @@ class ColorSelectActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
handleIntent()
|
||||
binding = MtActivityColorSelectBinding.inflate(layoutInflater).also {
|
||||
MtActivityColorSelectBinding.inflate(layoutInflater).also {
|
||||
binding = it
|
||||
setUpUI(it)
|
||||
ViewUtils.excludePaddingClippableViewFromNavigationBar(it.colorSettingRecyclerView)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
binding = null
|
||||
}
|
||||
|
||||
private fun handleIntent() {
|
||||
mTitle = intent.getStringExtra("title") ?: getString(R.string.mt_color_picker_title)
|
||||
}
|
||||
@@ -104,7 +100,7 @@ class ColorSelectActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private fun setUpToolbarColors() {
|
||||
val toolbar = binding!!.toolbar
|
||||
val toolbar = binding.toolbar
|
||||
val aimColor = when {
|
||||
ColorUtils.isLuminanceLight(mCurrentColor) -> getColor(R.color.day)
|
||||
else -> getColor(R.color.night)
|
||||
@@ -121,7 +117,7 @@ class ColorSelectActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private fun setColorWithAnimation(view: View, colorTo: Int) {
|
||||
binding!!.appBarContainer.setBackgroundColor(mCurrentColor)
|
||||
binding.appBarContainer.setBackgroundColor(mCurrentColor)
|
||||
view.setBackgroundColor(colorTo)
|
||||
mCurrentColor = colorTo
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.webkit.WebView
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
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.QueryEvent
|
||||
import org.autojs.autojs.ui.main.ViewPagerFragment
|
||||
@@ -27,7 +28,7 @@ import org.greenrobot.eventbus.Subscribe
|
||||
*/
|
||||
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 mPreviousQuery: String? = null
|
||||
@@ -45,12 +46,12 @@ open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressed
|
||||
}
|
||||
|
||||
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?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding!!.ewebView.also { ewebView ->
|
||||
binding.ewebView.also { ewebView ->
|
||||
ewebView.webView.also { webView ->
|
||||
mWebView = webView
|
||||
WebViewUtils.adaptDarkMode(requireContext(), webView)
|
||||
@@ -107,11 +108,6 @@ open class DocumentationFragment : ViewPagerFragment(ROTATION_GONE), BackPressed
|
||||
EventBus.getDefault().unregister(this)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
binding = null
|
||||
}
|
||||
|
||||
override fun onPageShow() {
|
||||
super.onPageShow()
|
||||
mIsCurrentPageDocs = true
|
||||
|
||||
@@ -253,7 +253,7 @@ class EditorView : LinearLayout, OnHintClickListener, ClickCallback, ToolbarFrag
|
||||
private fun setMenuItemStatus(id: Int, enabled: Boolean) {
|
||||
mMenuItemStatus.put(id, enabled)
|
||||
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) {
|
||||
mNormalToolbar.setMenuItemStatus(id, enabled)
|
||||
} else {
|
||||
|
||||
@@ -8,11 +8,9 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.autojs.autojs.execution.ScriptExecution;
|
||||
import org.autojs.autojs.pio.PFiles;
|
||||
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.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 EditorView mEditorView;
|
||||
@@ -76,7 +74,6 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
||||
mDebugger.clearAllBreakpoints();
|
||||
}
|
||||
};
|
||||
private FragmentDebugToolbarBinding binding;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@@ -84,11 +81,9 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = FragmentDebugToolbarBinding.inflate(inflater, container, false);
|
||||
return binding.getRoot();
|
||||
protected FragmentDebugToolbarBinding createBinding(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container) {
|
||||
return FragmentDebugToolbarBinding.inflate(inflater, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,12 +116,6 @@ public class DebugToolbarFragment extends ToolbarFragment implements DebugCallba
|
||||
binding.resume.setOnClickListener(v -> resume());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
|
||||
private void setupEditor() {
|
||||
CodeEditor editor = mEditorView.editor;
|
||||
editor.setRedoUndoEnabled(false);
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
package org.autojs.autojs.ui.edit.toolbar;
|
||||
|
||||
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 org.autojs.autojs6.R;
|
||||
import org.autojs.autojs6.databinding.FragmentNormalToolbarBinding;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class NormalToolbarFragment extends ToolbarFragment {
|
||||
public class NormalToolbarFragment extends ToolbarFragment<FragmentNormalToolbarBinding> {
|
||||
|
||||
private FragmentNormalToolbarBinding binding;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = FragmentNormalToolbarBinding.inflate(inflater, container, false);
|
||||
return binding.getRoot();
|
||||
protected FragmentNormalToolbarBinding createBinding(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container) {
|
||||
return FragmentNormalToolbarBinding.inflate(inflater, container, false);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,27 +4,22 @@ 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 org.autojs.autojs6.R;
|
||||
import org.autojs.autojs6.databinding.FragmentSearchToolbarBinding;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
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";
|
||||
|
||||
private FragmentSearchToolbarBinding binding;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
binding = FragmentSearchToolbarBinding.inflate(inflater, container, false);
|
||||
return binding.getRoot();
|
||||
protected FragmentSearchToolbarBinding createBinding(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container) {
|
||||
return FragmentSearchToolbarBinding.inflate(inflater, container, false);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
package org.autojs.autojs.ui.edit.toolbar;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.view.View;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.viewbinding.ViewBinding;
|
||||
import org.autojs.autojs.ui.edit.EditorView;
|
||||
import org.autojs.autojs.ui.fragment.BaseViewBindingFragment;
|
||||
import org.autojs.autojs6.R;
|
||||
|
||||
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 {
|
||||
void onToolbarMenuItemClick(int id);
|
||||
@@ -79,7 +77,7 @@ public abstract class ToolbarFragment extends Fragment implements View.OnClickLi
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
return mOnMenuItemLongClickListener != null &&
|
||||
mOnMenuItemLongClickListener.onToolbarMenuItemLongClick(v.getId());
|
||||
mOnMenuItemLongClickListener.onToolbarMenuItemLongClick(v.getId());
|
||||
}
|
||||
|
||||
public void setMenuItemStatus(int id, boolean enabled) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.PopupMenu
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
@@ -823,26 +822,20 @@ open class ExplorerView : ThemeColorSwipeRefreshLayout, SwipeRefreshLayout.OnRef
|
||||
}
|
||||
|
||||
internal inner class ExplorerPageViewHolder(itemView: View) : BindableViewHolder<Any>(itemView) {
|
||||
var mName: TextView
|
||||
var mDirDate: TextView
|
||||
var mOptions: View
|
||||
var mIcon: ImageView
|
||||
|
||||
private val binding = ExplorerDirectoryBinding.bind(itemView).also {
|
||||
it.item.setOnClickListener { withItemSelected { onItemClick() } }
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
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) {
|
||||
if (data !is ExplorerPage) return
|
||||
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) {
|
||||
val binding: ExplorerCategoryBinding = ExplorerCategoryBinding.bind(itemView)
|
||||
|
||||
private val binding = ExplorerCategoryBinding.bind(itemView)
|
||||
|
||||
private var mIsDir = false
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -361,6 +361,7 @@ class MainActivity : BaseActivity(), DelegateHost, HostActivity {
|
||||
return
|
||||
}
|
||||
if (!mBackPressObserver.onBackPressed(this)) {
|
||||
@Suppress("DEPRECATION")
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.autojs.autojs.app.tool.FloatingButtonTool
|
||||
import org.autojs.autojs.app.tool.JsonSocketClientTool
|
||||
import org.autojs.autojs.app.tool.JsonSocketServerTool
|
||||
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.IgnoreBatteryOptimizationsPermission
|
||||
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.JsonSocketClient
|
||||
import org.autojs.autojs.pluginclient.JsonSocketServer
|
||||
import org.autojs.autojs.core.pref.Pref
|
||||
import org.autojs.autojs.service.AccessibilityService
|
||||
import org.autojs.autojs.service.ForegroundService
|
||||
import org.autojs.autojs.service.NotificationService
|
||||
import org.autojs.autojs.theme.app.ColorSelectActivity
|
||||
import org.autojs.autojs.ui.floating.CircularMenu
|
||||
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.settings.AboutActivity
|
||||
import org.autojs.autojs.ui.settings.PreferencesActivity
|
||||
@@ -52,7 +53,7 @@ import java.lang.ref.WeakReference
|
||||
*/
|
||||
open class DrawerFragment : Fragment() {
|
||||
|
||||
private var binding: FragmentDrawerBinding? = null
|
||||
private val binding by viewBinding(FragmentDrawerBinding::bind)
|
||||
|
||||
private var privateDrawerMenu: RecyclerView? = 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? {
|
||||
return FragmentDrawerBinding.inflate(inflater, container, false).also { binding = it }.root
|
||||
return FragmentDrawerBinding.inflate(inflater, container, false).root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
mDrawerMenu = binding!!.drawerMenu
|
||||
mDrawerMenu = binding.drawerMenu
|
||||
initMenuItems()
|
||||
initMenuItemStates()
|
||||
setupListeners()
|
||||
}
|
||||
|
||||
private fun setupListeners() {
|
||||
binding!!.settings.setOnClickListener { view ->
|
||||
binding.settings.setOnClickListener { view ->
|
||||
startActivity(
|
||||
Intent(view.context, PreferencesActivity::class.java)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
)
|
||||
}
|
||||
binding!!.restart.setOnClickListener { mActivity.rebirth() }
|
||||
binding!!.exit.setOnClickListener { mActivity.exitCompletely() }
|
||||
binding.restart.setOnClickListener { mActivity.rebirth() }
|
||||
binding.exit.setOnClickListener { mActivity.exitCompletely() }
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@@ -410,7 +411,6 @@ open class DrawerFragment : Fragment() {
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
binding = null
|
||||
privateDrawerMenu = null
|
||||
privateContext = null
|
||||
privateActivity = null
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.autojs.autojs.model.script.Scripts
|
||||
import org.autojs.autojs.tool.SimpleObserver
|
||||
import org.autojs.autojs.ui.common.ScriptOperations
|
||||
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.OnFloatingActionButtonClickListener
|
||||
import org.autojs.autojs.ui.main.MainActivity
|
||||
@@ -44,7 +45,7 @@ import org.greenrobot.eventbus.Subscribe
|
||||
open class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickListener, ViewStatesManageable {
|
||||
|
||||
private var mBottomInset: Int = 0
|
||||
private var binding: FragmentExplorerBinding? = null
|
||||
private val binding by viewBinding(FragmentExplorerBinding::bind)
|
||||
|
||||
private var mExplorerView: ExplorerView? = 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? {
|
||||
return FragmentExplorerBinding.inflate(inflater, container, false).also { binding = it }.root
|
||||
return FragmentExplorerBinding.inflate(inflater, container, false).root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
@@ -65,7 +66,7 @@ open class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickL
|
||||
mBottomInset = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom
|
||||
insets
|
||||
}
|
||||
mExplorerView = binding!!.itemList.also { explorerView ->
|
||||
mExplorerView = binding.itemList.also { explorerView ->
|
||||
explorerView.setOnItemClickListener(object : ExplorerView.OnItemClickListener {
|
||||
override fun onItemClick(view: View?, item: ExplorerItem) {
|
||||
when {
|
||||
@@ -190,7 +191,6 @@ open class ExplorerFragment : ViewPagerFragment(0), OnFloatingActionButtonClickL
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
binding = null
|
||||
mExplorerView = null
|
||||
mFloatingActionMenu = null
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.view.ViewGroup
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
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.ViewStatesManageable
|
||||
import org.autojs.autojs.ui.widget.SimpleAdapterDataObserver
|
||||
@@ -21,7 +22,7 @@ import org.autojs.autojs6.databinding.FragmentTaskManagerBinding
|
||||
*/
|
||||
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 mSwipeRefreshLayout: SwipeRefreshLayout? = null
|
||||
@@ -31,13 +32,13 @@ open class TaskManagerFragment : ViewPagerFragment(45), ViewStatesManageable {
|
||||
}
|
||||
|
||||
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?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
mSwipeRefreshLayout = binding!!.swipeRefreshLayout
|
||||
mTaskListRecyclerView = binding!!.taskList.also { recyclerView ->
|
||||
mSwipeRefreshLayout = binding.swipeRefreshLayout
|
||||
mTaskListRecyclerView = binding.taskList.also { recyclerView ->
|
||||
recyclerView.adapter?.registerAdapterDataObserver(object : SimpleAdapterDataObserver() {
|
||||
override fun onSomethingChanged() {
|
||||
// To do something here maybe some day.
|
||||
@@ -75,7 +76,6 @@ open class TaskManagerFragment : ViewPagerFragment(45), ViewStatesManageable {
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
binding = null
|
||||
mTaskListRecyclerView = null
|
||||
mSwipeRefreshLayout = null
|
||||
}
|
||||
|
||||
@@ -17,11 +17,9 @@ import org.autojs.autojs6.databinding.SelectLauncherShortcutBinding
|
||||
*/
|
||||
class LauncherShortcutsPreference : MaterialPreference {
|
||||
|
||||
private var binding: SelectLauncherShortcutBinding? = null
|
||||
|
||||
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)
|
||||
.customView(binding.root, true)
|
||||
@@ -79,11 +77,6 @@ class LauncherShortcutsPreference : MaterialPreference {
|
||||
super.onClick()
|
||||
}
|
||||
|
||||
override fun onDetached() {
|
||||
super.onDetached()
|
||||
binding = null
|
||||
}
|
||||
|
||||
private fun showShortcutsSelectionDialog() {
|
||||
if (!mDialog.isShowing) mDialog.show()
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.widget.LinearLayout
|
||||
import org.autojs.autojs.ui.BaseActivity
|
||||
import org.autojs.autojs.ui.floating.FloatyWindowManger
|
||||
import org.autojs.autojs.ui.main.MainActivity
|
||||
@@ -20,8 +19,6 @@ class SplashActivity : BaseActivity() {
|
||||
|
||||
override val handleStatusBarThemeColorAutomatically = false
|
||||
|
||||
private var binding: ActivitySplashBinding? = null
|
||||
|
||||
private var mAlreadyEnterNextActivity = false
|
||||
private var mPaused = false
|
||||
|
||||
@@ -30,8 +27,7 @@ class SplashActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val binding = ActivitySplashBinding.inflate(layoutInflater).also { binding = it }
|
||||
setContentView(binding.root)
|
||||
setContentView(ActivitySplashBinding.inflate(layoutInflater).root)
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
mHandler = Looper.myLooper()?.let { Handler(it) } ?: Handler()
|
||||
@@ -53,11 +49,6 @@ class SplashActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
binding = null
|
||||
}
|
||||
|
||||
private fun enterNextActivity() {
|
||||
if (!mAlreadyEnterNextActivity && !mPaused) {
|
||||
mAlreadyEnterNextActivity = true
|
||||
@@ -68,7 +59,7 @@ class SplashActivity : BaseActivity() {
|
||||
|
||||
companion object {
|
||||
|
||||
const val INIT_TIMEOUT: Long = 1000
|
||||
const val INIT_TIMEOUT = 1000L
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package org.autojs.autojs.ui.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
@@ -11,47 +11,50 @@ import androidx.core.content.ContextCompat
|
||||
import org.autojs.autojs.theme.ThemeColorManager
|
||||
import org.autojs.autojs.util.DrawableUtils
|
||||
import org.autojs.autojs6.R
|
||||
import org.autojs.autojs6.databinding.ToolbarMenuItemBinding
|
||||
|
||||
/**
|
||||
* Created by Stardust on Jan 29, 2017.
|
||||
*/
|
||||
class ToolbarMenuItem : LinearLayout {
|
||||
|
||||
private val mColorDisabled: Int
|
||||
get() = when (ThemeColorManager.isThemeColorLuminanceLight()) {
|
||||
true -> ContextCompat.getColor(context, R.color.toolbar_menu_item_disabled_dark)
|
||||
else -> ContextCompat.getColor(context, R.color.toolbar_menu_item_disabled_light)
|
||||
}
|
||||
private val mColorEnabled: Int
|
||||
private lateinit var mImageView: ImageView
|
||||
private var mTextView: TextView
|
||||
|
||||
private val enabledDrawable by lazy {
|
||||
mImageView.drawable
|
||||
}
|
||||
|
||||
private val disabledDrawable by lazy {
|
||||
DrawableUtils.setDrawableColorFilterSrcIn(enabledDrawable, colorDisabled)
|
||||
}
|
||||
|
||||
private val colorEnabled: Int
|
||||
get() = when (ThemeColorManager.isThemeColorLuminanceLight()) {
|
||||
true -> ContextCompat.getColor(context, R.color.toolbar_menu_item_enabled_dark)
|
||||
else -> ContextCompat.getColor(context, R.color.toolbar_menu_item_enabled_light)
|
||||
}
|
||||
|
||||
private var mImageView: ImageView
|
||||
private var mTextView: TextView
|
||||
private var mEnabledDrawable: Drawable? = null
|
||||
private var mDisabledDrawable: Drawable? = null
|
||||
private val colorDisabled: Int
|
||||
get() = when (ThemeColorManager.isThemeColorLuminanceLight()) {
|
||||
true -> ContextCompat.getColor(context, R.color.toolbar_menu_item_disabled_dark)
|
||||
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) {
|
||||
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)
|
||||
@@ -59,22 +62,11 @@ class ToolbarMenuItem : LinearLayout {
|
||||
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
||||
|
||||
override fun setEnabled(enabled: Boolean) {
|
||||
if (enabled != isEnabled) {
|
||||
super.setEnabled(enabled)
|
||||
ensureEnabledDrawable()
|
||||
ensureDisabledDrawable()
|
||||
mImageView.setImageDrawable(if (enabled) mEnabledDrawable else mDisabledDrawable)
|
||||
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
|
||||
if (isEnabled == enabled) return
|
||||
super.setEnabled(enabled)
|
||||
mImageView.setImageDrawable(if (enabled) enabledDrawable else disabledDrawable)
|
||||
mImageView.imageTintList = ColorStateList.valueOf(if (enabled) colorEnabled else colorDisabled)
|
||||
mTextView.setTextColor(if (enabled) colorEnabled else colorDisabled)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user