Removed unrequired code
This commit is contained in:
parent
d7fa3ca4dc
commit
65711c22a3
|
@ -10,7 +10,6 @@ import android.os.Bundle
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import com.simplemobiletools.clock.BuildConfig
|
import com.simplemobiletools.clock.BuildConfig
|
||||||
import com.simplemobiletools.clock.R
|
import com.simplemobiletools.clock.R
|
||||||
import com.simplemobiletools.clock.adapters.ViewPagerAdapter
|
import com.simplemobiletools.clock.adapters.ViewPagerAdapter
|
||||||
|
@ -20,8 +19,6 @@ import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.commons.models.FAQItem
|
import com.simplemobiletools.commons.models.FAQItem
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import me.grantland.widget.AutofitHelper
|
import me.grantland.widget.AutofitHelper
|
||||||
|
|
||||||
class MainActivity : SimpleActivity() {
|
class MainActivity : SimpleActivity() {
|
||||||
|
|
|
@ -9,6 +9,8 @@ import android.media.AudioAttributes
|
||||||
import android.media.AudioManager.STREAM_ALARM
|
import android.media.AudioManager.STREAM_ALARM
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import android.text.SpannableString
|
import android.text.SpannableString
|
||||||
import android.text.format.DateFormat
|
import android.text.format.DateFormat
|
||||||
|
@ -311,17 +313,12 @@ fun Context.getClosestEnabledAlarmString(result: (String) -> Unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getEnabledAlarms(enabledAlarms: (List<Alarm>?) -> Unit) {
|
fun Context.getEnabledAlarms(enabledAlarms: (List<Alarm>?) -> Unit) {
|
||||||
ensureBackgroundThreadWithResult(
|
ensureBackgroundThread {
|
||||||
task = {
|
val alarms = dbHelper.getEnabledAlarms()
|
||||||
dbHelper.getEnabledAlarms()
|
Handler(Looper.getMainLooper()).post {
|
||||||
},
|
|
||||||
callback = { alarms ->
|
|
||||||
enabledAlarms.invoke(alarms)
|
enabledAlarms.invoke(alarms)
|
||||||
},
|
|
||||||
onError = {
|
|
||||||
enabledAlarms.invoke(null)
|
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.rescheduleEnabledAlarms() {
|
fun Context.rescheduleEnabledAlarms() {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import com.simplemobiletools.clock.R
|
import com.simplemobiletools.clock.R
|
||||||
import com.simplemobiletools.clock.activities.MainActivity
|
import com.simplemobiletools.clock.activities.MainActivity
|
||||||
import com.simplemobiletools.clock.activities.SimpleActivity
|
import com.simplemobiletools.clock.activities.SimpleActivity
|
||||||
|
@ -24,8 +23,6 @@ import com.simplemobiletools.commons.helpers.SORT_BY_DATE_CREATED
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.models.AlarmSound
|
import com.simplemobiletools.commons.models.AlarmSound
|
||||||
import kotlinx.android.synthetic.main.fragment_alarm.view.*
|
import kotlinx.android.synthetic.main.fragment_alarm.view.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
class AlarmFragment : Fragment(), ToggleAlarmInterface {
|
||||||
private var alarms = ArrayList<Alarm>()
|
private var alarms = ArrayList<Alarm>()
|
||||||
|
|
|
@ -241,40 +241,3 @@ fun getTimeDifferenceInMinutes(currentTimeInMinutes: Int, alarmTimeInMinutes: In
|
||||||
minutesInADay - (currentTimeInMinutes - minutesUntilAlarm)
|
minutesInADay - (currentTimeInMinutes - minutesUntilAlarm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs tasks that you want on a background thread and returns the result or error
|
|
||||||
* @param task: Callable to add code that should execute on a background thread
|
|
||||||
* @param callback: Gives back the result from the task after it has completed executing on the Main thread
|
|
||||||
* @param onError: Gives the error thrown if any by the Callable on the Main thread
|
|
||||||
*/
|
|
||||||
fun <T> ensureBackgroundThreadWithResult(
|
|
||||||
task: Callable<T>,
|
|
||||||
callback: (T) -> Unit,
|
|
||||||
onError: ((Throwable) -> Unit)? = null
|
|
||||||
) {
|
|
||||||
val executor = if (isOnMainThread()) {
|
|
||||||
Executors.newSingleThreadExecutor()
|
|
||||||
} else {
|
|
||||||
Executors.newFixedThreadPool(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
val handler = Handler(Looper.getMainLooper())
|
|
||||||
|
|
||||||
val future = executor.submit(task)
|
|
||||||
|
|
||||||
executor.submit {
|
|
||||||
try {
|
|
||||||
val result = future.get()
|
|
||||||
handler.post {
|
|
||||||
callback(result)
|
|
||||||
}
|
|
||||||
} catch (t: Throwable) {
|
|
||||||
handler.post {
|
|
||||||
onError?.invoke(t)
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
executor.shutdown()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue