|
@@ -1,12 +1,11 @@
|
|
|
package com.sduduzog.slimlauncher.ui.main
|
|
package com.sduduzog.slimlauncher.ui.main
|
|
|
|
|
|
|
|
import android.animation.ObjectAnimator
|
|
import android.animation.ObjectAnimator
|
|
|
-import android.content.ActivityNotFoundException
|
|
|
|
|
-import android.content.Context
|
|
|
|
|
-import android.content.Intent
|
|
|
|
|
|
|
+import android.content.*
|
|
|
import android.net.Uri
|
|
import android.net.Uri
|
|
|
import android.os.Build
|
|
import android.os.Build
|
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
|
|
|
+import android.provider.AlarmClock
|
|
|
import android.provider.MediaStore
|
|
import android.provider.MediaStore
|
|
|
import android.provider.Settings
|
|
import android.provider.Settings
|
|
|
import android.util.Log
|
|
import android.util.Log
|
|
@@ -15,28 +14,26 @@ import android.view.View
|
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
import android.widget.FrameLayout
|
|
import android.widget.FrameLayout
|
|
|
import androidx.fragment.app.Fragment
|
|
import androidx.fragment.app.Fragment
|
|
|
-import androidx.fragment.app.FragmentManager
|
|
|
|
|
-import androidx.fragment.app.FragmentPagerAdapter
|
|
|
|
|
import androidx.navigation.Navigation
|
|
import androidx.navigation.Navigation
|
|
|
import com.daasuu.ei.Ease
|
|
import com.daasuu.ei.Ease
|
|
|
import com.daasuu.ei.EasingInterpolator
|
|
import com.daasuu.ei.EasingInterpolator
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
|
|
-import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_COLLAPSED
|
|
|
|
|
-import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HALF_EXPANDED
|
|
|
|
|
import com.sduduzog.slimlauncher.MainActivity
|
|
import com.sduduzog.slimlauncher.MainActivity
|
|
|
import com.sduduzog.slimlauncher.R
|
|
import com.sduduzog.slimlauncher.R
|
|
|
import kotlinx.android.synthetic.main.main_bottom_sheet.*
|
|
import kotlinx.android.synthetic.main.main_bottom_sheet.*
|
|
|
import kotlinx.android.synthetic.main.main_content.*
|
|
import kotlinx.android.synthetic.main.main_content.*
|
|
|
|
|
+import java.text.SimpleDateFormat
|
|
|
|
|
+import java.util.*
|
|
|
|
|
|
|
|
|
|
|
|
|
class MainFragment : Fragment() {
|
|
class MainFragment : Fragment() {
|
|
|
|
|
|
|
|
- private lateinit var sheetBehavior: BottomSheetBehavior<FrameLayout>
|
|
|
|
|
- private var mSectionsPagerAdapter: SectionsPagerAdapter? = null
|
|
|
|
|
-
|
|
|
|
|
@Suppress("PropertyName")
|
|
@Suppress("PropertyName")
|
|
|
val TAG: String = "MainFragment"
|
|
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?,
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
|
|
savedInstanceState: Bundle?): View {
|
|
savedInstanceState: Bundle?): View {
|
|
@@ -46,8 +43,9 @@ class MainFragment : Fragment() {
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
|
|
super.onActivityCreated(savedInstanceState)
|
|
super.onActivityCreated(savedInstanceState)
|
|
|
Log.d(TAG, "onActivityCreated")
|
|
Log.d(TAG, "onActivityCreated")
|
|
|
- mSectionsPagerAdapter = SectionsPagerAdapter(childFragmentManager)
|
|
|
|
|
- container.adapter = mSectionsPagerAdapter
|
|
|
|
|
|
|
+ adapter = HomeAppsAdapter(this)
|
|
|
|
|
+ mainAppsList.adapter = adapter
|
|
|
|
|
+
|
|
|
sheetBehavior = BottomSheetBehavior.from(bottomSheet)
|
|
sheetBehavior = BottomSheetBehavior.from(bottomSheet)
|
|
|
optionsView.alpha = 0.0f
|
|
optionsView.alpha = 0.0f
|
|
|
setEventListeners()
|
|
setEventListeners()
|
|
@@ -56,9 +54,18 @@ class MainFragment : Fragment() {
|
|
|
override fun onStart() {
|
|
override fun onStart() {
|
|
|
super.onStart()
|
|
super.onStart()
|
|
|
Log.d(TAG, "onStart")
|
|
Log.d(TAG, "onStart")
|
|
|
|
|
+ receiver = ClockReceiver()
|
|
|
|
|
+ activity?.registerReceiver(receiver, IntentFilter(Intent.ACTION_TIME_TICK))
|
|
|
|
|
+
|
|
|
doBounceAnimation(ivExpand)
|
|
doBounceAnimation(ivExpand)
|
|
|
- sheetBehavior.state = STATE_COLLAPSED
|
|
|
|
|
- mSectionsPagerAdapter?.notifyDataSetChanged()
|
|
|
|
|
|
|
+ sheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ override fun onResume() {
|
|
|
|
|
+ super.onResume()
|
|
|
|
|
+ Log.d(TAG, "onResume")
|
|
|
|
|
+ updateUi()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun onAttach(context: Context?) {
|
|
override fun onAttach(context: Context?) {
|
|
@@ -66,45 +73,29 @@ class MainFragment : Fragment() {
|
|
|
with(context as MainActivity) {
|
|
with(context as MainActivity) {
|
|
|
this.onBackPressedListener = object : MainActivity.OnBackPressedListener {
|
|
this.onBackPressedListener = object : MainActivity.OnBackPressedListener {
|
|
|
override fun onBackPressed() {
|
|
override fun onBackPressed() {
|
|
|
- sheetBehavior.state = STATE_COLLAPSED
|
|
|
|
|
|
|
+ sheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- 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))
|
|
|
|
|
|
|
+ override fun onStop() {
|
|
|
|
|
+ super.onStop()
|
|
|
|
|
+ activity?.unregisterReceiver(receiver)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private fun setEventListeners() {
|
|
private fun setEventListeners() {
|
|
|
bottomSheet.setOnClickListener {
|
|
bottomSheet.setOnClickListener {
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ clockTextView.setOnClickListener {
|
|
|
|
|
+ try{
|
|
|
|
|
+ val intent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
|
|
|
|
|
+ intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
|
+ startActivity(intent)
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ // Do nothing
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
sheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
|
sheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
|
|
|
override fun onSlide(p0: View, p1: Float) {
|
|
override fun onSlide(p0: View, p1: Float) {
|
|
@@ -118,7 +109,7 @@ class MainFragment : Fragment() {
|
|
|
|
|
|
|
|
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
|
override fun onStateChanged(bottomSheet: View, newState: Int) {
|
|
|
iconTray.visibility = View.GONE
|
|
iconTray.visibility = View.GONE
|
|
|
- if (newState == STATE_COLLAPSED) {
|
|
|
|
|
|
|
+ if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
|
|
|
iconTray.visibility = View.VISIBLE
|
|
iconTray.visibility = View.VISIBLE
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -132,6 +123,7 @@ class MainFragment : Fragment() {
|
|
|
}
|
|
}
|
|
|
} else changeLauncherText.visibility = View.GONE
|
|
} else changeLauncherText.visibility = View.GONE
|
|
|
aboutText.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_openAboutFragment))
|
|
aboutText.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_openAboutFragment))
|
|
|
|
|
+ notesText.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_openNotesListFragment))
|
|
|
ivCall.setOnClickListener {
|
|
ivCall.setOnClickListener {
|
|
|
try {
|
|
try {
|
|
|
val intent = Intent(Intent.ACTION_DIAL)
|
|
val intent = Intent(Intent.ACTION_DIAL)
|
|
@@ -150,26 +142,63 @@ class MainFragment : Fragment() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ivExpand.setOnClickListener {
|
|
ivExpand.setOnClickListener {
|
|
|
- if (sheetBehavior.state == STATE_COLLAPSED) sheetBehavior.state = STATE_HALF_EXPANDED
|
|
|
|
|
|
|
+ if (sheetBehavior.state == BottomSheetBehavior.STATE_COLLAPSED) sheetBehavior.state = BottomSheetBehavior.STATE_HALF_EXPANDED
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- inner class SectionsPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
|
|
|
|
|
-
|
|
|
|
|
- override fun getItem(position: Int): Fragment {
|
|
|
|
|
- return HomeFragment.newInstance()
|
|
|
|
|
|
|
+ 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))
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- override fun getCount(): Int {
|
|
|
|
|
- // Show 3 total pages.
|
|
|
|
|
- return 1
|
|
|
|
|
|
|
+ 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()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fun updateUi() {
|
|
|
|
|
+ val twenty4Hour = context?.getSharedPreferences(getString(R.string.prefs_settings), Context.MODE_PRIVATE)
|
|
|
|
|
+ ?.getBoolean(getString(R.string.prefs_settings_key_clock_type), false)
|
|
|
|
|
+ val date = Date()
|
|
|
|
|
+ if (twenty4Hour as Boolean) {
|
|
|
|
|
+ val fWatchTime = SimpleDateFormat("HH:mm", Locale.ENGLISH)
|
|
|
|
|
+ clockTextView.text = fWatchTime.format(date)
|
|
|
|
|
+ clockAmPm.visibility = View.GONE
|
|
|
|
|
+ } else {
|
|
|
|
|
+ val fWatchTime = SimpleDateFormat("hh:mm", Locale.ENGLISH)
|
|
|
|
|
+ val fWatchTimeAP = SimpleDateFormat("aa", Locale.ENGLISH)
|
|
|
|
|
+ clockTextView.text = fWatchTime.format(date)
|
|
|
|
|
+ clockAmPm.text = fWatchTimeAP.format(date)
|
|
|
|
|
+ clockAmPm.visibility = View.VISIBLE
|
|
|
}
|
|
}
|
|
|
|
|
+ val fWatchDate = SimpleDateFormat("EEE, MMM dd", Locale.ENGLISH)
|
|
|
|
|
+ dateTextView.text = fWatchDate.format(date)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- override fun getPageTitle(position: Int): CharSequence? {
|
|
|
|
|
- when (position) {
|
|
|
|
|
- 0 -> return "Home"
|
|
|
|
|
- }
|
|
|
|
|
- return null
|
|
|
|
|
|
|
+ inner class ClockReceiver : BroadcastReceiver() {
|
|
|
|
|
+ override fun onReceive(ctx: Context?, intent: Intent?) {
|
|
|
|
|
+ updateUi()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|