forked from SimpleMobileTools/Simple-Clock
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from coxtor/silentAlarm
Silent alarm
- Loading branch information
Showing
93 changed files
with
1,483 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
app/src/main/kotlin/com/simplemobiletools/clock/adapters/ChildAlarmsAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.simplemobiletools.clock.adapters | ||
|
||
import android.app.TimePickerDialog | ||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.SeekBar | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.simplemobiletools.clock.R | ||
import com.simplemobiletools.clock.extensions.config | ||
import com.simplemobiletools.clock.extensions.getFormattedTime | ||
import com.simplemobiletools.clock.models.Alarm | ||
import com.simplemobiletools.commons.extensions.getDialogTheme | ||
import kotlinx.android.synthetic.main.item_child_alarm.view.* | ||
import com.simplemobiletools.commons.extensions.toast | ||
import kotlin.math.abs | ||
|
||
class ChildAlarmsAdapter (var items: List<Alarm>, var shownItems: List<Int>, val parentAlarm: Alarm, val context: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { | ||
|
||
var alarmsToDelete = ArrayList<Alarm>() | ||
|
||
override fun getItemCount(): Int { | ||
return shownItems.size | ||
} | ||
|
||
fun updateItems(newItems: List<Alarm>, newShownItems: List<Int>) { | ||
items = newItems | ||
shownItems = newShownItems | ||
notifyDataSetChanged() | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
return ViewHolder (LayoutInflater.from(context).inflate(R.layout.item_child_alarm, parent, false)) | ||
} | ||
|
||
|
||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { | ||
var childAlarm : Alarm = items.get(shownItems.get(position)) | ||
var time = context.getFormattedTime(childAlarm.timeInMinutes *60, false, true) | ||
holder.itemView.tv_child_alarm_info.setTextColor(context!!.config.textColor) | ||
holder.itemView.tv_child_alarm_info.setText(time) | ||
holder.itemView.switch_toggle_silent_alarm.isChecked = childAlarm.isEnabled | ||
|
||
val timeSetListener = TimePickerDialog.OnTimeSetListener { view, hourOfDay, minute -> | ||
childAlarm.timeInMinutes = hourOfDay * 60 + minute | ||
var time = context.getFormattedTime(childAlarm.timeInMinutes *60, false, true) | ||
holder.itemView.tv_child_alarm_info.setText(time) | ||
} | ||
|
||
holder.itemView.tv_child_alarm_info.setOnClickListener { | ||
if(parentAlarm.timeInMinutes != childAlarm.timeInMinutes) | ||
TimePickerDialog(context, context.getDialogTheme(), timeSetListener, childAlarm.timeInMinutes / 60, childAlarm.timeInMinutes % 60, context.config.use24HourFormat).show() | ||
else | ||
TimePickerDialog(context, context.getDialogTheme(), timeSetListener, parentAlarm.timeInMinutes / 60, parentAlarm.timeInMinutes % 60, context.config.use24HourFormat).show() | ||
} | ||
|
||
holder.itemView.ib_delete_child_alarm.setOnClickListener { | ||
items.get(shownItems.get(position)).isEnabled = false | ||
alarmsToDelete.add(items.get(shownItems.get(position))) | ||
updateItems(items, shownItems.minus(position)) | ||
notifyDataSetChanged() | ||
} | ||
|
||
|
||
holder.itemView.switch_toggle_silent_alarm.setOnClickListener { | ||
items[position].isEnabled = !items[position].isEnabled | ||
} | ||
|
||
|
||
} | ||
|
||
fun addItem(alarm: Alarm) { | ||
updateItems(items.plus(alarm), shownItems.plus(shownItems.lastIndex+1)) | ||
//updateItems(items.plus(alarm), items.plus(alarm).indices.toList()) | ||
} | ||
|
||
} | ||
|
||
class ViewHolder (view: View) : RecyclerView.ViewHolder(view) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SilentAlarmInfoDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.simplemobiletools.clock.dialogs | ||
|
||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.fragment.app.DialogFragment | ||
import com.simplemobiletools.clock.R | ||
|
||
class SilentAlarmInfoDialog : DialogFragment() { | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
return activity?.let { | ||
// Use the Builder class for convenient dialog construction | ||
val builder = AlertDialog.Builder(it) | ||
builder.setTitle(R.string.silent_alarm_dialog_title) | ||
builder.setMessage(R.string.silent_alarm_info) | ||
.setNeutralButton(R.string.ok, DialogInterface.OnClickListener{ dialog: DialogInterface?, which: Int -> }) | ||
builder.create() | ||
} ?: throw IllegalStateException("Activity cannot be null") | ||
} | ||
} |
Oops, something went wrong.