|
|
@@ -1,10 +1,15 @@
|
|
|
package com.sduduzog.slimlauncher.ui.main
|
|
|
|
|
|
+import android.animation.ObjectAnimator
|
|
|
import android.arch.lifecycle.Observer
|
|
|
import android.arch.lifecycle.ViewModelProviders
|
|
|
import android.content.*
|
|
|
+import android.net.Uri
|
|
|
import android.os.Build
|
|
|
import android.os.Bundle
|
|
|
+import android.support.constraint.ConstraintLayout
|
|
|
+import android.support.design.widget.BottomSheetBehavior
|
|
|
+import android.support.design.widget.BottomSheetBehavior.*
|
|
|
import android.support.v4.app.Fragment
|
|
|
import android.util.Log
|
|
|
import android.view.LayoutInflater
|
|
|
@@ -12,17 +17,24 @@ import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
import android.widget.Toast
|
|
|
import androidx.navigation.Navigation
|
|
|
+import com.daasuu.ei.Ease
|
|
|
+import com.daasuu.ei.EasingInterpolator
|
|
|
+import com.sduduzog.slimlauncher.MainViewModel
|
|
|
import com.sduduzog.slimlauncher.R
|
|
|
import com.sduduzog.slimlauncher.data.HomeApp
|
|
|
-import kotlinx.android.synthetic.main.main_fragment.*
|
|
|
+import kotlinx.android.synthetic.main.main_bottom_sheet.*
|
|
|
+import kotlinx.android.synthetic.main.main_content.*
|
|
|
import java.text.SimpleDateFormat
|
|
|
import java.util.*
|
|
|
|
|
|
+
|
|
|
class MainFragment : Fragment() {
|
|
|
|
|
|
private lateinit var viewModel: MainViewModel
|
|
|
private lateinit var receiver: BroadcastReceiver
|
|
|
private lateinit var adapter: MainAppsAdapter
|
|
|
+ private lateinit var sheetBehavior: BottomSheetBehavior<ConstraintLayout>
|
|
|
+ private lateinit var themeChooser: ThemeChooserDialog
|
|
|
|
|
|
private val TAG: String = "MainFragment"
|
|
|
|
|
|
@@ -35,22 +47,59 @@ class MainFragment : Fragment() {
|
|
|
super.onActivityCreated(savedInstanceState)
|
|
|
viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)
|
|
|
adapter = MainAppsAdapter(mutableSetOf(), InteractionHandler())
|
|
|
+ themeChooser = ThemeChooserDialog(context!!)
|
|
|
mainAppsList.adapter = adapter
|
|
|
viewModel.homeApps.observe(this, Observer {
|
|
|
if (it != null) {
|
|
|
adapter.setApps(it)
|
|
|
}
|
|
|
})
|
|
|
- settingsButton.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_openSettingsFragment))
|
|
|
clockTextView.setOnClickListener {
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
try {
|
|
|
- startActivity(Intent(android.provider.AlarmClock.ACTION_SHOW_ALARMS))
|
|
|
- }catch (e: Exception){
|
|
|
+ val intent = Intent(android.provider.AlarmClock.ACTION_SHOW_ALARMS)
|
|
|
+ intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
+ startActivity(intent)
|
|
|
+ } catch (e: Exception) {
|
|
|
Log.e(TAG, e.message)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ bottomSheet.alpha = 0.0f
|
|
|
+ sheetBehavior = BottomSheetBehavior.from(bottomSheet)
|
|
|
+
|
|
|
+ sheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
|
|
+ override fun onSlide(p0: View, p1: Float) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onStateChanged(bottomSheet: View, newState: Int) {
|
|
|
+ ivExpand.visibility = View.INVISIBLE
|
|
|
+ when (newState) {
|
|
|
+ STATE_COLLAPSED -> {
|
|
|
+ bottomSheet.animate().alpha(0.0f).duration = 100
|
|
|
+ ivExpand.visibility = View.VISIBLE
|
|
|
+ }
|
|
|
+ STATE_EXPANDED -> {
|
|
|
+ bottomSheet.animate().alpha(1.0f).duration = 50
|
|
|
+ }
|
|
|
+ STATE_DRAGGING -> {
|
|
|
+ bottomSheet.alpha = 1.0f
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ bottomSheet.setOnClickListener { }
|
|
|
+ changeThemeText.setOnClickListener { changeTheme() }
|
|
|
+ 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(android.provider.Settings.ACTION_HOME_SETTINGS))
|
|
|
+ }
|
|
|
+ } else changeLauncherText.visibility = View.INVISIBLE
|
|
|
+ aboutText.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_openAboutFragment))
|
|
|
updateUi()
|
|
|
}
|
|
|
|
|
|
@@ -58,6 +107,8 @@ class MainFragment : Fragment() {
|
|
|
super.onStart()
|
|
|
receiver = ClockReceiver()
|
|
|
activity?.registerReceiver(receiver, IntentFilter(Intent.ACTION_TIME_TICK))
|
|
|
+ doBounceAnimation(ivExpand)
|
|
|
+ sheetBehavior.state = STATE_COLLAPSED
|
|
|
}
|
|
|
|
|
|
override fun onStop() {
|
|
|
@@ -77,6 +128,7 @@ class MainFragment : Fragment() {
|
|
|
val date = Date()
|
|
|
clockTextView.text = fWatchTime.format(date)
|
|
|
dateTextView.text = fWatchDate.format(date)
|
|
|
+ doBounceAnimation(ivExpand)
|
|
|
}
|
|
|
|
|
|
inner class InteractionHandler : OnListFragmentInteractionListener {
|
|
|
@@ -100,4 +152,38 @@ class MainFragment : Fragment() {
|
|
|
interface OnListFragmentInteractionListener {
|
|
|
fun onLaunch(item: HomeApp)
|
|
|
}
|
|
|
+
|
|
|
+ private fun doBounceAnimation(targetView: View) {
|
|
|
+ val animator = ObjectAnimator.ofFloat(targetView, "translationY", 0f, -20f, 0f)
|
|
|
+ animator.interpolator = EasingInterpolator(Ease.QUINT_OUT)
|
|
|
+ animator.startDelay = 1000
|
|
|
+ animator.duration = 1000
|
|
|
+ animator.repeatCount = 1
|
|
|
+ animator.start()
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 changeTheme() {
|
|
|
+ themeChooser.show(fragmentManager, TAG)
|
|
|
+ }
|
|
|
}
|