|
|
@@ -23,7 +23,10 @@ import android.view.View.OnClickListener
|
|
|
import android.view.ViewGroup
|
|
|
import android.view.inputmethod.EditorInfo
|
|
|
import android.view.inputmethod.InputMethodManager
|
|
|
+import android.widget.EditText
|
|
|
+import android.widget.ImageView
|
|
|
import android.widget.PopupMenu
|
|
|
+import android.widget.TextView
|
|
|
import android.widget.Toast
|
|
|
import androidx.activity.result.ActivityResultLauncher
|
|
|
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
|
|
|
@@ -33,6 +36,7 @@ import androidx.fragment.app.viewModels
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
import androidx.navigation.Navigation
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
+import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.simplauncher.datastore.ClockType
|
|
|
import com.simplauncher.datastore.SearchBarPosition
|
|
|
import com.simplauncher.datastore.UnlauncherApp
|
|
|
@@ -48,18 +52,6 @@ import com.simplauncher.utils.BaseFragment
|
|
|
import com.simplauncher.utils.OnLaunchAppListener
|
|
|
import com.simplauncher.utils.isSystemApp
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
|
|
-import kotlinx.android.synthetic.main.home_fragment_content.app_drawer_edit_text
|
|
|
-import kotlinx.android.synthetic.main.home_fragment_content.app_drawer_fragment_list
|
|
|
-import kotlinx.android.synthetic.main.home_fragment_content.home_fragment_analog_time
|
|
|
-import kotlinx.android.synthetic.main.home_fragment_content.home_fragment_bin_time
|
|
|
-import kotlinx.android.synthetic.main.home_fragment_content.home_fragment_call
|
|
|
-import kotlinx.android.synthetic.main.home_fragment_content.home_fragment_camera
|
|
|
-import kotlinx.android.synthetic.main.home_fragment_content.home_fragment_date
|
|
|
-import kotlinx.android.synthetic.main.home_fragment_content.home_fragment_list
|
|
|
-import kotlinx.android.synthetic.main.home_fragment_content.home_fragment_list_exp
|
|
|
-import kotlinx.android.synthetic.main.home_fragment_content.home_fragment_options
|
|
|
-import kotlinx.android.synthetic.main.home_fragment_content.home_fragment_time
|
|
|
-import kotlinx.android.synthetic.main.home_fragment_default.home_fragment
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.launch
|
|
|
import java.text.SimpleDateFormat
|
|
|
@@ -80,6 +72,20 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
private lateinit var appDrawerAdapter: AppDrawerAdapter
|
|
|
private lateinit var uninstallAppLauncher: ActivityResultLauncher<Intent>
|
|
|
|
|
|
+ // View references (content views come from <merge> include, so ViewBinding can't resolve them)
|
|
|
+ private var homeFragmentView: MotionLayout? = null
|
|
|
+ private var appDrawerEditText: EditText? = null
|
|
|
+ private var appDrawerFragmentList: RecyclerView? = null
|
|
|
+ private var homeFragmentTime: TextView? = null
|
|
|
+ private var homeFragmentDate: TextView? = null
|
|
|
+ private var homeFragmentAnalogTime: AnalogClockView? = null
|
|
|
+ private var homeFragmentBinTime: BinaryClockView? = null
|
|
|
+ private var homeFragmentList: RecyclerView? = null
|
|
|
+ private var homeFragmentListExp: RecyclerView? = null
|
|
|
+ private var homeFragmentCall: ImageView? = null
|
|
|
+ private var homeFragmentOptions: ImageView? = null
|
|
|
+ private var homeFragmentCamera: ImageView? = null
|
|
|
+
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
uninstallAppLauncher = registerForActivityResult(StartActivityForResult()) { refreshApps() }
|
|
|
@@ -93,15 +99,44 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
SearchBarPosition.top -> R.layout.home_fragment_default
|
|
|
else -> R.layout.home_fragment_default
|
|
|
}
|
|
|
- return inflater.inflate(layout, container, false)
|
|
|
+ val view = inflater.inflate(layout, container, false)
|
|
|
+ homeFragmentView = view as MotionLayout
|
|
|
+ appDrawerEditText = view.findViewById(R.id.app_drawer_edit_text)
|
|
|
+ appDrawerFragmentList = view.findViewById(R.id.app_drawer_fragment_list)
|
|
|
+ homeFragmentTime = view.findViewById(R.id.home_fragment_time)
|
|
|
+ homeFragmentDate = view.findViewById(R.id.home_fragment_date)
|
|
|
+ homeFragmentAnalogTime = view.findViewById(R.id.home_fragment_analog_time)
|
|
|
+ homeFragmentBinTime = view.findViewById(R.id.home_fragment_bin_time)
|
|
|
+ homeFragmentList = view.findViewById(R.id.home_fragment_list)
|
|
|
+ homeFragmentListExp = view.findViewById(R.id.home_fragment_list_exp)
|
|
|
+ homeFragmentCall = view.findViewById(R.id.home_fragment_call)
|
|
|
+ homeFragmentOptions = view.findViewById(R.id.home_fragment_options)
|
|
|
+ homeFragmentCamera = view.findViewById(R.id.home_fragment_camera)
|
|
|
+ return view
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onDestroyView() {
|
|
|
+ super.onDestroyView()
|
|
|
+ homeFragmentView = null
|
|
|
+ appDrawerEditText = null
|
|
|
+ appDrawerFragmentList = null
|
|
|
+ homeFragmentTime = null
|
|
|
+ homeFragmentDate = null
|
|
|
+ homeFragmentAnalogTime = null
|
|
|
+ homeFragmentBinTime = null
|
|
|
+ homeFragmentList = null
|
|
|
+ homeFragmentListExp = null
|
|
|
+ homeFragmentCall = null
|
|
|
+ homeFragmentOptions = null
|
|
|
+ homeFragmentCamera = null
|
|
|
}
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
val adapter1 = HomeAdapter(this, unlauncherDataSource)
|
|
|
val adapter2 = HomeAdapter(this, unlauncherDataSource)
|
|
|
- home_fragment_list.adapter = adapter1
|
|
|
- home_fragment_list_exp.adapter = adapter2
|
|
|
+ homeFragmentList!!.adapter = adapter1
|
|
|
+ homeFragmentListExp!!.adapter = adapter2
|
|
|
|
|
|
val unlauncherAppsRepo = unlauncherDataSource.unlauncherAppsRepo
|
|
|
|
|
|
@@ -129,16 +164,16 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
|
|
|
setEventListeners()
|
|
|
|
|
|
- app_drawer_fragment_list.adapter = appDrawerAdapter
|
|
|
+ appDrawerFragmentList!!.adapter = appDrawerAdapter
|
|
|
|
|
|
unlauncherDataSource.corePreferencesRepo.liveData().observe(viewLifecycleOwner){ corePreferences ->
|
|
|
- app_drawer_edit_text.visibility = if (corePreferences.showSearchBar) View.VISIBLE else View.GONE
|
|
|
+ appDrawerEditText!!.visibility = if (corePreferences.showSearchBar) View.VISIBLE else View.GONE
|
|
|
|
|
|
val clockType = corePreferences.clockType
|
|
|
- home_fragment_time.visibility = if(clockType == ClockType.digital) View.VISIBLE else View.GONE
|
|
|
- home_fragment_analog_time.visibility = if(clockType == ClockType.analog) View.VISIBLE else View.GONE
|
|
|
- home_fragment_bin_time.visibility = if(clockType == ClockType.binary) View.VISIBLE else View.GONE
|
|
|
- home_fragment_date.visibility = if(clockType != ClockType.none) View.VISIBLE else View.GONE
|
|
|
+ homeFragmentTime!!.visibility = if(clockType == ClockType.digital) View.VISIBLE else View.GONE
|
|
|
+ homeFragmentAnalogTime!!.visibility = if(clockType == ClockType.analog) View.VISIBLE else View.GONE
|
|
|
+ homeFragmentBinTime!!.visibility = if(clockType == ClockType.binary) View.VISIBLE else View.GONE
|
|
|
+ homeFragmentDate!!.visibility = if(clockType != ClockType.none) View.VISIBLE else View.GONE
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -148,7 +183,7 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
activity?.registerReceiver(receiver, IntentFilter(Intent.ACTION_TIME_TICK))
|
|
|
}
|
|
|
|
|
|
- override fun getFragmentView(): ViewGroup = home_fragment
|
|
|
+ override fun getFragmentView(): ViewGroup = homeFragmentView!!
|
|
|
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
@@ -160,9 +195,9 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
}
|
|
|
|
|
|
// scroll back to the top if user returns to this fragment
|
|
|
- val layoutManager = app_drawer_fragment_list.layoutManager as LinearLayoutManager
|
|
|
+ val layoutManager = appDrawerFragmentList!!.layoutManager as LinearLayoutManager
|
|
|
if (layoutManager.findFirstCompletelyVisibleItemPosition() != 0) {
|
|
|
- app_drawer_fragment_list.scrollToPosition(0)
|
|
|
+ appDrawerFragmentList!!.scrollToPosition(0)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -192,11 +227,11 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
// Do nothing, we've failed :(
|
|
|
}
|
|
|
}
|
|
|
- home_fragment_time.setOnClickListener(launchShowAlarms)
|
|
|
- home_fragment_analog_time.setOnClickListener(launchShowAlarms)
|
|
|
- home_fragment_bin_time.setOnClickListener(launchShowAlarms)
|
|
|
+ homeFragmentTime!!.setOnClickListener(launchShowAlarms)
|
|
|
+ homeFragmentAnalogTime!!.setOnClickListener(launchShowAlarms)
|
|
|
+ homeFragmentBinTime!!.setOnClickListener(launchShowAlarms)
|
|
|
|
|
|
- home_fragment_date.setOnClickListener {
|
|
|
+ homeFragmentDate!!.setOnClickListener {
|
|
|
try {
|
|
|
val builder = CalendarContract.CONTENT_URI.buildUpon().appendPath("time")
|
|
|
val intent = Intent(Intent.ACTION_VIEW, builder.build())
|
|
|
@@ -210,9 +245,9 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
unlauncherDataSource.quickButtonPreferencesRepo.liveData()
|
|
|
.observe(viewLifecycleOwner) { prefs ->
|
|
|
val leftButtonIcon = QuickButtonPreferencesRepository.RES_BY_ICON.getValue(prefs.leftButton.iconId)
|
|
|
- home_fragment_call.setImageResource(leftButtonIcon)
|
|
|
+ homeFragmentCall!!.setImageResource(leftButtonIcon)
|
|
|
if (leftButtonIcon != R.drawable.ic_empty) {
|
|
|
- home_fragment_call.setOnClickListener { view ->
|
|
|
+ homeFragmentCall!!.setOnClickListener { view ->
|
|
|
try {
|
|
|
val pm = context?.packageManager!!
|
|
|
val intent = Intent(Intent.ACTION_DIAL)
|
|
|
@@ -228,9 +263,9 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
}
|
|
|
|
|
|
val centerButtonIcon = QuickButtonPreferencesRepository.RES_BY_ICON.getValue(prefs.centerButton.iconId)
|
|
|
- home_fragment_options.setImageResource(centerButtonIcon)
|
|
|
+ homeFragmentOptions!!.setImageResource(centerButtonIcon)
|
|
|
if (centerButtonIcon != R.drawable.ic_empty) {
|
|
|
- home_fragment_options.setOnClickListener(
|
|
|
+ homeFragmentOptions!!.setOnClickListener(
|
|
|
Navigation.createNavigateOnClickListener(
|
|
|
R.id.action_homeFragment_to_optionsFragment
|
|
|
)
|
|
|
@@ -238,9 +273,9 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
}
|
|
|
|
|
|
val rightButtonIcon = QuickButtonPreferencesRepository.RES_BY_ICON.getValue(prefs.rightButton.iconId)
|
|
|
- home_fragment_camera.setImageResource(rightButtonIcon)
|
|
|
+ homeFragmentCamera!!.setImageResource(rightButtonIcon)
|
|
|
if (rightButtonIcon != R.drawable.ic_empty) {
|
|
|
- home_fragment_camera.setOnClickListener {
|
|
|
+ homeFragmentCamera!!.setOnClickListener {
|
|
|
try {
|
|
|
val intent = Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA)
|
|
|
launchActivity(it, intent)
|
|
|
@@ -251,20 +286,20 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- app_drawer_edit_text.addTextChangedListener(appDrawerAdapter.searchBoxListener)
|
|
|
+ appDrawerEditText!!.addTextChangedListener(appDrawerAdapter.searchBoxListener)
|
|
|
|
|
|
- app_drawer_edit_text.setOnEditorActionListener { _, actionId, _ ->
|
|
|
+ appDrawerEditText!!.setOnEditorActionListener { _, actionId, _ ->
|
|
|
if(actionId == EditorInfo.IME_ACTION_DONE && appDrawerAdapter.itemCount > 0) {
|
|
|
val firstApp = appDrawerAdapter.getFirstApp()
|
|
|
launchApp(firstApp.packageName, firstApp.className, firstApp.userSerial)
|
|
|
- home_fragment.transitionToStart()
|
|
|
+ homeFragmentView!!.transitionToStart()
|
|
|
true
|
|
|
} else {
|
|
|
false
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- home_fragment.setTransitionListener(object : TransitionListener {
|
|
|
+ homeFragmentView!!.setTransitionListener(object : TransitionListener {
|
|
|
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
|
|
|
val inputMethodManager = requireContext().getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
|
|
|
|
@@ -280,10 +315,10 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
// Check for preferences to open the keyboard
|
|
|
// only if the search field is shown
|
|
|
if (preferences.showSearchBar && preferences.activateKeyboardInDrawer) {
|
|
|
- app_drawer_edit_text.requestFocus()
|
|
|
+ appDrawerEditText!!.requestFocus()
|
|
|
// show the keyboard and set focus to the EditText when swiping down
|
|
|
inputMethodManager.showSoftInput(
|
|
|
- app_drawer_edit_text,
|
|
|
+ appDrawerEditText!!,
|
|
|
InputMethodManager.SHOW_IMPLICIT
|
|
|
)
|
|
|
}
|
|
|
@@ -309,8 +344,8 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
updateDate()
|
|
|
when (unlauncherDataSource.corePreferencesRepo.get().clockType) {
|
|
|
ClockType.digital -> updateClockDigital()
|
|
|
- ClockType.analog -> home_fragment_analog_time.updateClock()
|
|
|
- ClockType.binary -> home_fragment_bin_time.updateClock()
|
|
|
+ ClockType.analog -> homeFragmentAnalogTime!!.updateClock()
|
|
|
+ ClockType.binary -> homeFragmentBinTime!!.updateClock()
|
|
|
else -> {}
|
|
|
}
|
|
|
}
|
|
|
@@ -323,12 +358,12 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
2 -> SimpleDateFormat("h:mm aa", Locale.getDefault())
|
|
|
else -> DateFormat.getTimeFormat(context)
|
|
|
}
|
|
|
- home_fragment_time.text = fWatchTime.format(Date())
|
|
|
+ homeFragmentTime!!.text = fWatchTime.format(Date())
|
|
|
}
|
|
|
|
|
|
private fun updateDate() {
|
|
|
val fWatchDate = SimpleDateFormat(getString(R.string.main_date_format), Locale.getDefault())
|
|
|
- home_fragment_date.text = fWatchDate.format(Date())
|
|
|
+ homeFragmentDate!!.text = fWatchDate.format(Date())
|
|
|
}
|
|
|
|
|
|
override fun onLaunch(app: HomeApp, view: View) {
|
|
|
@@ -336,12 +371,12 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
}
|
|
|
|
|
|
override fun onBack(): Boolean {
|
|
|
- home_fragment.transitionToStart()
|
|
|
+ homeFragmentView!!.transitionToStart()
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
override fun onHome() {
|
|
|
- home_fragment.transitionToStart()
|
|
|
+ homeFragmentView!!.transitionToStart()
|
|
|
}
|
|
|
|
|
|
inner class ClockReceiver : BroadcastReceiver() {
|
|
|
@@ -365,9 +400,9 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
}
|
|
|
|
|
|
private fun resetAppDrawerEditText() {
|
|
|
- app_drawer_edit_text.clearComposingText()
|
|
|
- app_drawer_edit_text.setText("")
|
|
|
- app_drawer_edit_text.clearFocus()
|
|
|
+ appDrawerEditText!!.clearComposingText()
|
|
|
+ appDrawerEditText!!.setText("")
|
|
|
+ appDrawerEditText!!.clearFocus()
|
|
|
}
|
|
|
|
|
|
inner class AppDrawerListener {
|
|
|
@@ -426,7 +461,7 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
|
|
|
fun onAppClicked(app: UnlauncherApp) {
|
|
|
launchApp(app.packageName, app.className, app.userSerial)
|
|
|
- home_fragment.transitionToStart()
|
|
|
+ homeFragmentView!!.transitionToStart()
|
|
|
}
|
|
|
}
|
|
|
}
|