|
|
@@ -8,11 +8,9 @@ import android.provider.MediaStore
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
-import androidx.core.app.ActivityOptionsCompat
|
|
|
import androidx.lifecycle.Observer
|
|
|
import androidx.lifecycle.ViewModelProviders
|
|
|
import androidx.navigation.Navigation
|
|
|
-import com.sduduzog.slimlauncher.MainActivity
|
|
|
import com.sduduzog.slimlauncher.R
|
|
|
import com.sduduzog.slimlauncher.adapters.HomeAdapter
|
|
|
import com.sduduzog.slimlauncher.data.HomeApp
|
|
|
@@ -24,7 +22,7 @@ import java.text.SimpleDateFormat
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
|
-class HomeFragment : BaseFragment(), MainActivity.OnBackPressedListener, OnLaunchAppListener {
|
|
|
+class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
|
|
|
private lateinit var receiver: BroadcastReceiver
|
|
|
private lateinit var viewModel: MainViewModel
|
|
|
@@ -68,7 +66,7 @@ class HomeFragment : BaseFragment(), MainActivity.OnBackPressedListener, OnLaunc
|
|
|
}
|
|
|
|
|
|
override fun getFragmentView(): View {
|
|
|
- return main_fragment2
|
|
|
+ return home_fragment
|
|
|
}
|
|
|
|
|
|
override fun onResume() {
|
|
|
@@ -76,47 +74,20 @@ class HomeFragment : BaseFragment(), MainActivity.OnBackPressedListener, OnLaunc
|
|
|
updateUi()
|
|
|
}
|
|
|
|
|
|
- override fun onAttach(context: Context?) {
|
|
|
- super.onAttach(context)
|
|
|
- with(context as MainActivity) {
|
|
|
- this.onBackPressedListener = this@HomeFragment
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- override fun onDetach() {
|
|
|
- super.onDetach()
|
|
|
- with(context as MainActivity) {
|
|
|
- this.onBackPressedListener = null
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
override fun onStop() {
|
|
|
super.onStop()
|
|
|
activity?.unregisterReceiver(receiver)
|
|
|
}
|
|
|
|
|
|
- override fun onBackPress() {
|
|
|
- }
|
|
|
-
|
|
|
- override fun onBackPressed() {
|
|
|
- // Do nothing
|
|
|
- }
|
|
|
-
|
|
|
private fun setEventListeners() {
|
|
|
|
|
|
-
|
|
|
home_fragment_time.setOnClickListener {
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
try {
|
|
|
val intent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
|
|
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
- val left = 0
|
|
|
- val top = 0
|
|
|
- val width = it.measuredWidth
|
|
|
- val height = it.measuredHeight
|
|
|
- val opts = ActivityOptionsCompat.makeClipRevealAnimation(it, left, top, width, height)
|
|
|
if (intent.resolveActivity(context!!.packageManager) != null)
|
|
|
- startActivity(intent, opts.toBundle())
|
|
|
+ launchActivity(it, intent)
|
|
|
} catch (e: ActivityNotFoundException) {
|
|
|
// Do nothing, we've failed :(
|
|
|
}
|
|
|
@@ -128,12 +99,7 @@ class HomeFragment : BaseFragment(), MainActivity.OnBackPressedListener, OnLaunc
|
|
|
val intent = Intent(Intent.ACTION_MAIN)
|
|
|
intent.addCategory(Intent.CATEGORY_APP_CALENDAR)
|
|
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
- val left = 0
|
|
|
- val top = 0
|
|
|
- val width = it.measuredWidth
|
|
|
- val height = it.measuredHeight
|
|
|
- val opts = ActivityOptionsCompat.makeClipRevealAnimation(it, left, top, width, height)
|
|
|
- startActivity(intent, opts.toBundle())
|
|
|
+ launchActivity(it, intent)
|
|
|
} catch (e: ActivityNotFoundException) {
|
|
|
// Do nothing, we've failed :(
|
|
|
}
|
|
|
@@ -142,12 +108,7 @@ class HomeFragment : BaseFragment(), MainActivity.OnBackPressedListener, OnLaunc
|
|
|
home_fragment_call.setOnClickListener {
|
|
|
try {
|
|
|
val intent = Intent(Intent.ACTION_DIAL)
|
|
|
- val left = 0
|
|
|
- val top = 0
|
|
|
- val width = it.measuredWidth
|
|
|
- val height = it.measuredHeight
|
|
|
- val opts = ActivityOptionsCompat.makeClipRevealAnimation(it, left, top, width, height)
|
|
|
- startActivity(intent, opts.toBundle())
|
|
|
+ launchActivity(it, intent)
|
|
|
} catch (e: Exception) {
|
|
|
// Do nothing
|
|
|
}
|
|
|
@@ -192,6 +153,10 @@ class HomeFragment : BaseFragment(), MainActivity.OnBackPressedListener, OnLaunc
|
|
|
launchActivity(view, intent)
|
|
|
}
|
|
|
|
|
|
+ override fun onBack(): Boolean {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
inner class ClockReceiver : BroadcastReceiver() {
|
|
|
override fun onReceive(ctx: Context?, intent: Intent?) {
|
|
|
updateUi()
|