diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/App.kt b/app/src/main/kotlin/com/simplemobiletools/clock/App.kt index f627a09..7bc445f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/App.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/App.kt @@ -5,7 +5,6 @@ import android.app.NotificationManager import android.content.Context import android.os.Build import android.os.CountDownTimer -import android.util.Log import androidx.annotation.RequiresApi import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleObserver @@ -71,17 +70,14 @@ class App : Application(), LifecycleObserver { @Subscribe(threadMode = ThreadMode.MAIN) fun onMessageEvent(event: TimerEvent.Reset) { - Log.w(TAG, "onMessageEvent: $event") updateTimerState(event.timerId, TimerState.Idle) countDownTimers[event.timerId]?.cancel() } @Subscribe(threadMode = ThreadMode.MAIN) fun onMessageEvent(event: TimerEvent.Start) { - Log.w(TAG, "onMessageEvent: $event") val countDownTimer = object : CountDownTimer(event.duration, 1000) { override fun onTick(tick: Long) { - Log.d(TAG, "onMessageEvent--> $tick") updateTimerState(event.timerId, TimerState.Running(event.duration, tick)) } @@ -95,7 +91,6 @@ class App : Application(), LifecycleObserver { @Subscribe(threadMode = ThreadMode.MAIN) fun onMessageEvent(event: TimerEvent.Finish) { - Log.w(TAG, "onMessageEvent: $event") timerHelper.getTimer(event.timerId) { timer -> val pendingIntent = getOpenTimerTabIntent(event.timerId) val notification = getTimerNotification(timer, pendingIntent, false) @@ -107,7 +102,6 @@ class App : Application(), LifecycleObserver { @Subscribe(threadMode = ThreadMode.MAIN) fun onMessageEvent(event: TimerEvent.Pause) { - Log.w(TAG, "onMessageEvent: $event") timerHelper.getTimer(event.timerId) { timer -> updateTimerState(event.timerId, TimerState.Paused(event.duration, (timer.state as TimerState.Running).tick)) countDownTimers[event.timerId]?.cancel() @@ -117,17 +111,9 @@ class App : Application(), LifecycleObserver { private fun updateTimerState(timerId: Long, state: TimerState) { timerHelper.getTimer(timerId) { timer -> val newTimer = timer.copy(state = state) - Log.w(TAG, "updateTimerState: $newTimer") timerHelper.insertOrUpdateTimer(newTimer) { EventBus.getDefault().post(TimerEvent.Refresh(timerId)) - timerHelper.getTimer(timerId) { - Log.e(TAG, "updated timer $it") - } } } } - - companion object { - private const val TAG = "App" - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt index 81fe0ec..015e49a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt @@ -3,7 +3,6 @@ package com.simplemobiletools.clock.activities import android.content.Intent import android.graphics.drawable.ColorDrawable import android.os.Bundle -import android.util.Log import android.view.Menu import android.view.MenuItem import android.view.WindowManager @@ -24,7 +23,6 @@ import kotlinx.android.synthetic.main.activity_main.main_tabs_holder import kotlinx.android.synthetic.main.activity_main.view_pager class MainActivity : SimpleActivity() { - private val TAG = "MainActivity" private var storedTextColor = 0 private var storedBackgroundColor = 0 private var storedPrimaryColor = 0 @@ -32,7 +30,6 @@ class MainActivity : SimpleActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - intent.extras?.printAllItems("onCreate") appLaunched(BuildConfig.APPLICATION_ID) storeStateVariables() initFragments() @@ -103,13 +100,11 @@ class MainActivity : SimpleActivity() { } override fun onNewIntent(intent: Intent) { - intent.extras?.printAllItems("onNewIntent") if (intent.extras?.containsKey(OPEN_TAB) == true) { val tabToOpen = intent.getIntExtra(OPEN_TAB, TAB_CLOCK) view_pager.setCurrentItem(tabToOpen, false) if (tabToOpen == TAB_TIMER) { val timerId = intent.getLongExtra(TIMER_ID, INVALID_TIMER_ID) - Log.e(TAG, "onNewIntent: TIMER ID: $timerId") (view_pager.adapter as ViewPagerAdapter).updateTimerPosition(timerId) } } @@ -157,9 +152,7 @@ class MainActivity : SimpleActivity() { val tabToOpen = intent.getIntExtra(OPEN_TAB, config.lastUsedViewPagerPage) intent.removeExtra(OPEN_TAB) if (tabToOpen == TAB_TIMER) { - Log.e(TAG, "initFragments: TIMER") val timerId = intent.getLongExtra(TIMER_ID, INVALID_TIMER_ID) - Log.e(TAG, "initFragments: TIMER ID: $timerId") viewPagerAdapter.updateTimerPosition(timerId) } view_pager.currentItem = tabToOpen @@ -213,9 +206,3 @@ class MainActivity : SimpleActivity() { startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true) } } - -fun Bundle.printAllItems(where:String) { - for (key in keySet()) { - Log.e(where, "Item: key: $key - value: ${get(key)}") - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/adapters/TimerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/clock/adapters/TimerAdapter.kt index 10d1ff1..4a920f1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/adapters/TimerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/adapters/TimerAdapter.kt @@ -2,7 +2,6 @@ package com.simplemobiletools.clock.adapters import android.media.AudioManager import android.media.RingtoneManager -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -21,7 +20,6 @@ import com.simplemobiletools.commons.extensions.getDefaultAlarmSound import com.simplemobiletools.commons.extensions.getFormattedDuration import com.simplemobiletools.commons.extensions.onTextChangeListener import com.simplemobiletools.commons.models.AlarmSound -import kotlin.math.roundToInt import kotlinx.android.synthetic.main.item_timer.view.* class TimerAdapter( @@ -29,6 +27,18 @@ class TimerAdapter( private val onRefresh: () -> Unit, ) : ListAdapter(diffUtil) { + companion object { + private val diffUtil = object : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: Timer, newItem: Timer): Boolean { + return oldItem.id == newItem.id + } + + override fun areContentsTheSame(oldItem: Timer, newItem: Timer): Boolean { + return oldItem == newItem + } + } + } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TimerViewHolder { return TimerViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_timer, parent, false)) } @@ -45,7 +55,6 @@ class TimerAdapter( init { itemView.timer_label.onTextChangeListener { text -> - Log.w(TAG, "timer_label") updateTimer(getItemAt(adapterPosition).copy(label = text), false) } @@ -79,7 +88,6 @@ class TimerAdapter( } timer_vibrate_holder.setOnClickListener { - Log.w(TAG, "toggle") timer_vibrate.toggle() updateTimer(timer.copy(vibrate = timer_vibrate.isChecked), false) } @@ -127,35 +135,19 @@ class TimerAdapter( private fun changeDuration(timer: Timer) { MyTimePickerDialogDialog(activity, timer.seconds) { seconds -> val timerSeconds = if (seconds <= 0) 10 else seconds - Log.w(TAG, "changeDuration") updateTimer(timer.copy(seconds = timerSeconds)) } } fun updateAlarmSound(timer: Timer, alarmSound: AlarmSound) { - Log.w(TAG, "updateAlarmSound: $timer") updateTimer(timer.copy(soundTitle = alarmSound.title, soundUri = alarmSound.uri, channelId = null)) } private fun updateTimer(timer: Timer, refresh: Boolean = true) { - Log.w(TAG, "updateTimer: $timer") activity.timerHelper.insertOrUpdateTimer(timer){ if (refresh) { onRefresh.invoke() } } } - - companion object { - private const val TAG = "TimerAdapter" - private val diffUtil = object : DiffUtil.ItemCallback() { - override fun areItemsTheSame(oldItem: Timer, newItem: Timer): Boolean { - return oldItem.id == newItem.id - } - - override fun areContentsTheSame(oldItem: Timer, newItem: Timer): Boolean { - return oldItem == newItem - } - } - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/adapters/ViewPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/clock/adapters/ViewPagerAdapter.kt index e2177b5..bc2d9a9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/adapters/ViewPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/adapters/ViewPagerAdapter.kt @@ -1,6 +1,5 @@ package com.simplemobiletools.clock.adapters -import android.util.Log import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager @@ -55,10 +54,7 @@ class ViewPagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) { (fragments[TAB_TIMER] as? TimerFragment)?.updateAlarmSound(alarmSound) } - private val TAG = "ViewPagerAdapter" - fun updateTimerPosition(timerId: Long) { - Log.e(TAG, "updateTimerPosition: $timerId") (fragments[TAB_TIMER] as? TimerFragment)?.updatePosition(timerId) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt index d2e7fa4..a30e159 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/extensions/Context.kt @@ -13,7 +13,6 @@ import android.net.Uri import android.os.PowerManager import android.text.SpannableString import android.text.style.RelativeSizeSpan -import android.util.Log import android.widget.Toast import androidx.core.app.AlarmManagerCompat import androidx.core.app.NotificationCompat @@ -21,7 +20,6 @@ import com.simplemobiletools.clock.R import com.simplemobiletools.clock.activities.ReminderActivity import com.simplemobiletools.clock.activities.SnoozeReminderActivity import com.simplemobiletools.clock.activities.SplashActivity -import com.simplemobiletools.clock.activities.printAllItems import com.simplemobiletools.clock.databases.AppDatabase import com.simplemobiletools.clock.helpers.* import com.simplemobiletools.clock.interfaces.TimerDao @@ -146,7 +144,6 @@ fun Context.getOpenTimerTabIntent(timerId: Long): PendingIntent { val intent = getLaunchIntent() ?: Intent(this, SplashActivity::class.java) intent.putExtra(OPEN_TAB, TAB_TIMER) intent.putExtra(TIMER_ID, timerId) - intent.extras?.printAllItems("getOpenTimerTabIntent") return PendingIntent.getActivity(this, TIMER_NOTIF_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT) } @@ -263,7 +260,7 @@ fun Context.showAlarmNotification(alarm: Alarm) { scheduleNextAlarm(alarm, false) } } -private const val TAG = "ALARMMMM" + @SuppressLint("NewApi") fun Context.getTimerNotification(timer: Timer, pendingIntent: PendingIntent, addDeleteIntent: Boolean): Notification { var soundUri = timer.soundUri @@ -273,9 +270,6 @@ fun Context.getTimerNotification(timer: Timer, pendingIntent: PendingIntent, add grantReadUriPermission(soundUri) } - Log.w(TAG, "getTimerNotification: timerSOUNDURI=${timer.soundUri}") - Log.w(TAG, "getTimerNotification: soundUri=${soundUri}") - val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val channelId = timer.channelId ?: "simple_timer_channel_${soundUri}_${System.currentTimeMillis()}" timerHelper.insertOrUpdateTimer(timer.copy(channelId = channelId)) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/TimerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/TimerFragment.kt index 70719c3..f932288 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/TimerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/TimerFragment.kt @@ -2,7 +2,6 @@ package com.simplemobiletools.clock.fragments import android.graphics.Color import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -53,7 +52,6 @@ class TimerFragment : Fragment() { timer_view_pager.setPageTransformer { _, _ -> } timer_view_pager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() { override fun onPageSelected(position: Int) { - Log.i(TAG, "onPageSelected: $position") updateViews(position) indicator_view.setCurrentPosition(0) } @@ -115,24 +113,18 @@ class TimerFragment : Fragment() { val timer = timerAdapter.getItemAt(position) updateViewStates(timer.state) view.timer_play_pause.beVisible() - } else { - Log.e(TAG, "updateViews: position $position is greater than adapter itemCount ${timerAdapter.itemCount}") } } } private fun refreshTimers(scrollToLatest: Boolean = false) { activity?.timerHelper?.getTimers { timers -> - Log.d(TAG, "refreshTimers: $timers") timerAdapter.submitList(timers) { view.timer_view_pager.post { - Log.e(TAG, "submitted list: timerPositionToScrollTo=$timerPositionToScrollTo") if (timerPositionToScrollTo != INVALID_POSITION && timerAdapter.itemCount > timerPositionToScrollTo) { - Log.e(TAG, "scrolling to position=$timerPositionToScrollTo") view.timer_view_pager.setCurrentItem(timerPositionToScrollTo, false) timerPositionToScrollTo = INVALID_POSITION } else if (scrollToLatest) { - Log.e(TAG, "scrolling to latest") view.timer_view_pager.setCurrentItem(0, false) } updateViews(timer_view_pager.currentItem) @@ -148,7 +140,6 @@ class TimerFragment : Fragment() { @Subscribe(threadMode = ThreadMode.MAIN) fun onMessageEvent(event: TimerEvent.Refresh) { - Log.d(TAG, "onMessageEvent: $event") refreshTimers() } @@ -180,25 +171,17 @@ class TimerFragment : Fragment() { } fun updatePosition(timerId: Long) { - Log.e(TAG, "updatePosition TIMER: $timerId") activity?.timerHelper?.getTimers { timers -> val position = timers.indexOfFirst { it.id == timerId } - Log.e(TAG, "updatePosition POSITION: $position") if (position != INVALID_POSITION) { activity?.runOnUiThread { if (timerAdapter.itemCount > position) { - Log.e(TAG, "updatePosition now: $position") view.timer_view_pager.setCurrentItem(position, false) } else { - Log.e(TAG, "updatePosition later: $position") timerPositionToScrollTo = position } } } } } - - companion object { - private const val TAG = "TimerFragment" - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/TimerHelper.kt b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/TimerHelper.kt index adc0c2b..433d7e0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/helpers/TimerHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/helpers/TimerHelper.kt @@ -1,7 +1,6 @@ package com.simplemobiletools.clock.helpers import android.content.Context -import android.util.Log import com.simplemobiletools.clock.extensions.config import com.simplemobiletools.clock.extensions.timerDb import com.simplemobiletools.clock.models.Timer @@ -24,8 +23,7 @@ class TimerHelper(val context: Context) { fun insertOrUpdateTimer(timer: Timer, callback: () -> Unit = {}) { ensureBackgroundThread { - val id = timerDao.insertOrUpdateTimer(timer) - Log.d(TAG, "insertOrUpdateTimer: $id") + timerDao.insertOrUpdateTimer(timer) callback.invoke() } } @@ -57,8 +55,4 @@ class TimerHelper(val context: Context) { callback.invoke() } } - - companion object { - private const val TAG = "TimerHelper" - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/services/TimerService.kt b/app/src/main/kotlin/com/simplemobiletools/clock/services/TimerService.kt index 7a1053b..46e9441 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/services/TimerService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/services/TimerService.kt @@ -9,7 +9,6 @@ import android.content.Context import android.content.Intent import android.os.Build import android.os.IBinder -import android.util.Log import androidx.annotation.RequiresApi import androidx.core.app.NotificationCompat import com.simplemobiletools.clock.R @@ -20,9 +19,7 @@ import com.simplemobiletools.clock.helpers.INVALID_TIMER_ID import com.simplemobiletools.clock.helpers.TIMER_RUNNING_NOTIF_ID import com.simplemobiletools.clock.models.TimerEvent import com.simplemobiletools.clock.models.TimerState -import com.simplemobiletools.commons.extensions.getFormattedDuration import com.simplemobiletools.commons.helpers.isOreoPlus -import kotlin.math.roundToInt import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode @@ -114,17 +111,12 @@ class TimerService : Service() { .setChannelId(channelId) if (firstRunningTimerId != INVALID_TIMER_ID) { - Log.e(TAG, "notification: Setting content intent for $firstRunningTimerId" ) builder.setContentIntent(this.getOpenTimerTabIntent(firstRunningTimerId)) } builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) return builder.build() } - - companion object { - private const val TAG = "TimerService" - } } @RequiresApi(Build.VERSION_CODES.O)