|
|
@@ -1,27 +1,24 @@
|
|
|
package com.sduduzog.slimlauncher.ui.main
|
|
|
|
|
|
import android.animation.ObjectAnimator
|
|
|
-import android.content.*
|
|
|
-import android.net.Uri
|
|
|
-import android.os.Build
|
|
|
+import android.content.BroadcastReceiver
|
|
|
+import android.content.Context
|
|
|
+import android.content.Intent
|
|
|
+import android.content.IntentFilter
|
|
|
import android.os.Bundle
|
|
|
import android.provider.AlarmClock
|
|
|
import android.provider.MediaStore
|
|
|
-import android.provider.Settings
|
|
|
import android.util.Log
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
-import android.widget.FrameLayout
|
|
|
import androidx.fragment.app.Fragment
|
|
|
import androidx.navigation.Navigation
|
|
|
import com.daasuu.ei.Ease
|
|
|
import com.daasuu.ei.EasingInterpolator
|
|
|
-import com.google.android.material.bottomsheet.BottomSheetBehavior
|
|
|
import com.sduduzog.slimlauncher.MainActivity
|
|
|
import com.sduduzog.slimlauncher.R
|
|
|
-import kotlinx.android.synthetic.main.main_bottom_sheet.*
|
|
|
-import kotlinx.android.synthetic.main.main_content.*
|
|
|
+import kotlinx.android.synthetic.main.main_fragment.*
|
|
|
import java.text.SimpleDateFormat
|
|
|
import java.util.*
|
|
|
|
|
|
@@ -31,9 +28,7 @@ class MainFragment : Fragment() {
|
|
|
@Suppress("PropertyName")
|
|
|
val TAG: String = "MainFragment"
|
|
|
|
|
|
- private lateinit var adapter: HomeAppsAdapter
|
|
|
private lateinit var receiver: BroadcastReceiver
|
|
|
- private lateinit var sheetBehavior: BottomSheetBehavior<FrameLayout>
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
|
|
savedInstanceState: Bundle?): View {
|
|
|
@@ -42,29 +37,21 @@ class MainFragment : Fragment() {
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
|
|
super.onActivityCreated(savedInstanceState)
|
|
|
- Log.d(TAG, "onActivityCreated")
|
|
|
- adapter = HomeAppsAdapter(this)
|
|
|
- mainAppsList.adapter = adapter
|
|
|
-
|
|
|
- sheetBehavior = BottomSheetBehavior.from(bottomSheet)
|
|
|
- optionsView.alpha = 0.0f
|
|
|
+ mainAppsList.adapter = HomeAppsAdapter(this)
|
|
|
setEventListeners()
|
|
|
}
|
|
|
|
|
|
override fun onStart() {
|
|
|
super.onStart()
|
|
|
- Log.d(TAG, "onStart")
|
|
|
receiver = ClockReceiver()
|
|
|
activity?.registerReceiver(receiver, IntentFilter(Intent.ACTION_TIME_TICK))
|
|
|
|
|
|
doBounceAnimation(ivExpand)
|
|
|
- sheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
|
|
}
|
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
- Log.d(TAG, "onResume")
|
|
|
updateUi()
|
|
|
}
|
|
|
|
|
|
@@ -73,7 +60,6 @@ class MainFragment : Fragment() {
|
|
|
with(context as MainActivity) {
|
|
|
this.onBackPressedListener = object : MainActivity.OnBackPressedListener {
|
|
|
override fun onBackPressed() {
|
|
|
- sheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -85,11 +71,8 @@ class MainFragment : Fragment() {
|
|
|
}
|
|
|
|
|
|
private fun setEventListeners() {
|
|
|
- bottomSheet.setOnClickListener {
|
|
|
-
|
|
|
- }
|
|
|
clockTextView.setOnClickListener {
|
|
|
- try{
|
|
|
+ try {
|
|
|
val intent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
|
|
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
startActivity(intent)
|
|
|
@@ -97,34 +80,8 @@ class MainFragment : Fragment() {
|
|
|
// Do nothing
|
|
|
}
|
|
|
}
|
|
|
- sheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
|
|
- override fun onSlide(p0: View, p1: Float) {
|
|
|
- val multi = 3 * p1
|
|
|
- optionsView.alpha = multi
|
|
|
- optionsView.cardElevation = p1 * 8
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
- optionsView.elevation = p1 * 8
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- override fun onStateChanged(bottomSheet: View, newState: Int) {
|
|
|
- iconTray.visibility = View.GONE
|
|
|
- if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
|
|
|
- iconTray.visibility = View.VISIBLE
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- settingsText.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_openSettingsFragment))
|
|
|
- deviceSettingsText.setOnClickListener { openSettings() }
|
|
|
- rateAppText.setOnClickListener { rateApp() }
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
- changeLauncherText.setOnClickListener {
|
|
|
- startActivity(Intent(Settings.ACTION_HOME_SETTINGS))
|
|
|
- }
|
|
|
- } else changeLauncherText.visibility = View.GONE
|
|
|
- aboutText.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_openAboutFragment))
|
|
|
- notesText.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_openNotesListFragment))
|
|
|
- ivCall.setOnClickListener {
|
|
|
+ buttonDialer.setOnClickListener {
|
|
|
try {
|
|
|
val intent = Intent(Intent.ACTION_DIAL)
|
|
|
startActivity(intent)
|
|
|
@@ -132,7 +89,10 @@ class MainFragment : Fragment() {
|
|
|
Log.e(TAG, e.message)
|
|
|
}
|
|
|
}
|
|
|
- ivCamera.setOnClickListener {
|
|
|
+
|
|
|
+ ivExpand.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_openOptionsFragment))
|
|
|
+
|
|
|
+ buttonCamera.setOnClickListener {
|
|
|
try {
|
|
|
val intent = Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA)
|
|
|
startActivity(intent)
|
|
|
@@ -140,32 +100,9 @@ class MainFragment : Fragment() {
|
|
|
Log.e(TAG, e.message)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- ivExpand.setOnClickListener {
|
|
|
- if (sheetBehavior.state == BottomSheetBehavior.STATE_COLLAPSED) sheetBehavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- private fun rateApp() {
|
|
|
- val uri = Uri.parse("market://details?id=" + context?.packageName)
|
|
|
- val goToMarket = Intent(Intent.ACTION_VIEW, uri)
|
|
|
- goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY or
|
|
|
- Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
- goToMarket.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT)
|
|
|
- }
|
|
|
- try {
|
|
|
- startActivity(goToMarket)
|
|
|
- Log.d(TAG, goToMarket.data?.query)
|
|
|
- } catch (e: ActivityNotFoundException) {
|
|
|
- startActivity(Intent(Intent.ACTION_VIEW,
|
|
|
- Uri.parse("http://play.google.com/store/apps/details?id=" + context?.packageName)))
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- private fun openSettings() {
|
|
|
- startActivity(Intent(android.provider.Settings.ACTION_SETTINGS))
|
|
|
- }
|
|
|
|
|
|
private fun doBounceAnimation(targetView: View) {
|
|
|
val animator = ObjectAnimator.ofFloat(targetView, "translationY", 0f, -20f, 0f)
|
|
|
@@ -200,5 +137,4 @@ class MainFragment : Fragment() {
|
|
|
updateUi()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|