Merge "AOSP/DeskClock - Add Kotlin files for some of Ringtone directory"
diff --git a/Android.bp b/Android.bp
index fccb977..7776fe9 100644
--- a/Android.bp
+++ b/Android.bp
@@ -49,6 +49,12 @@
"src/**/deskclock/data/*.java",
"src/**/deskclock/events/*.java",
"src/**/deskclock/provider/*.java",
+ "src/**/deskclock/ringtone/AddCustomRingtoneHolder.java",
+ "src/**/deskclock/ringtone/AddCustomRingtoneViewHolder.java",
+ "src/**/deskclock/ringtone/CustomRingtoneHolder.java",
+ "src/**/deskclock/ringtone/HeaderHolder.java",
+ "src/**/deskclock/ringtone/HeaderViewHolder.java",
+ "src/**/deskclock/ringtone/RingtoneHolder.java",
"src/**/deskclock/settings/*.java",
"src/**/deskclock/stopwatch/*.java"
],
diff --git a/src/com/android/deskclock/ringtone/AddCustomRingtoneHolder.kt b/src/com/android/deskclock/ringtone/AddCustomRingtoneHolder.kt
new file mode 100644
index 0000000..675122b
--- /dev/null
+++ b/src/com/android/deskclock/ringtone/AddCustomRingtoneHolder.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.deskclock.ringtone
+
+import android.net.Uri
+import androidx.recyclerview.widget.RecyclerView.NO_ID
+
+import com.android.deskclock.ItemAdapter.ItemHolder
+
+internal class AddCustomRingtoneHolder : ItemHolder<Uri>(null, NO_ID) {
+ override fun getItemViewType(): Int {
+ return AddCustomRingtoneViewHolder.VIEW_TYPE_ADD_NEW
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/deskclock/ringtone/AddCustomRingtoneViewHolder.kt b/src/com/android/deskclock/ringtone/AddCustomRingtoneViewHolder.kt
new file mode 100644
index 0000000..69a245f
--- /dev/null
+++ b/src/com/android/deskclock/ringtone/AddCustomRingtoneViewHolder.kt
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.deskclock.ringtone
+
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.ImageView
+import android.widget.TextView
+
+import com.android.deskclock.ItemAdapter.ItemViewHolder
+import com.android.deskclock.R
+
+internal class AddCustomRingtoneViewHolder private constructor(itemView: View)
+ : ItemViewHolder<AddCustomRingtoneHolder?>(itemView), View.OnClickListener {
+
+ init {
+ itemView.setOnClickListener(this)
+ val selectedView = itemView.findViewById<View>(R.id.sound_image_selected)
+ selectedView.visibility = View.GONE
+ val nameView = itemView.findViewById<View>(R.id.ringtone_name) as TextView
+ nameView.text = itemView.context.getString(R.string.add_new_sound)
+ nameView.alpha = 0.63f
+ val imageView = itemView.findViewById<View>(R.id.ringtone_image) as ImageView
+ imageView.setImageResource(R.drawable.ic_add_white_24dp)
+ imageView.alpha = 0.63f
+ }
+
+ override fun onClick(view: View) {
+ notifyItemClicked(CLICK_ADD_NEW)
+ }
+
+ class Factory internal constructor(private val mInflater: LayoutInflater)
+ : ItemViewHolder.Factory {
+ override fun createViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder<*> {
+ val itemView =
+ mInflater.inflate(R.layout.ringtone_item_sound, parent, false)
+ return AddCustomRingtoneViewHolder(itemView)
+ }
+ }
+
+ companion object {
+ const val VIEW_TYPE_ADD_NEW = Int.MIN_VALUE
+ const val CLICK_ADD_NEW = VIEW_TYPE_ADD_NEW
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/deskclock/ringtone/CustomRingtoneHolder.kt b/src/com/android/deskclock/ringtone/CustomRingtoneHolder.kt
new file mode 100644
index 0000000..bd880ad
--- /dev/null
+++ b/src/com/android/deskclock/ringtone/CustomRingtoneHolder.kt
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.deskclock.ringtone
+
+import com.android.deskclock.data.CustomRingtone
+
+internal class CustomRingtoneHolder(ringtone: CustomRingtone)
+ : RingtoneHolder(ringtone.uri, ringtone.title, ringtone.hasPermissions()) {
+
+ override fun getItemViewType(): Int {
+ return RingtoneViewHolder.VIEW_TYPE_CUSTOM_SOUND
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/deskclock/ringtone/HeaderHolder.kt b/src/com/android/deskclock/ringtone/HeaderHolder.kt
new file mode 100644
index 0000000..ff7622c
--- /dev/null
+++ b/src/com/android/deskclock/ringtone/HeaderHolder.kt
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.deskclock.ringtone
+
+import android.net.Uri
+import androidx.annotation.StringRes
+import androidx.recyclerview.widget.RecyclerView.NO_ID
+
+import com.android.deskclock.ItemAdapter.ItemHolder
+
+internal class HeaderHolder(
+ @field:StringRes @get:StringRes
+ @param:StringRes val textResId: Int
+) : ItemHolder<Uri>(null, NO_ID) {
+
+ override fun getItemViewType(): Int {
+ return HeaderViewHolder.VIEW_TYPE_ITEM_HEADER
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/deskclock/ringtone/HeaderViewHolder.kt b/src/com/android/deskclock/ringtone/HeaderViewHolder.kt
new file mode 100644
index 0000000..3dd287f
--- /dev/null
+++ b/src/com/android/deskclock/ringtone/HeaderViewHolder.kt
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.deskclock.ringtone
+
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.TextView
+
+import com.android.deskclock.ItemAdapter.ItemViewHolder
+import com.android.deskclock.R
+
+internal class HeaderViewHolder private constructor(itemView: View)
+ : ItemViewHolder<HeaderHolder>(itemView) {
+ private val mItemHeader: TextView =
+ itemView.findViewById<View>(R.id.ringtone_item_header) as TextView
+
+ override fun onBindItemView(itemHolder: HeaderHolder) {
+ mItemHeader.setText(itemHolder.textResId)
+ }
+
+ class Factory internal constructor(private val mInflater: LayoutInflater)
+ : ItemViewHolder.Factory {
+ override fun createViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder<*> {
+ return HeaderViewHolder(mInflater.inflate(viewType, parent, false))
+ }
+ }
+
+ companion object {
+ const val VIEW_TYPE_ITEM_HEADER = R.layout.ringtone_item_header
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/deskclock/ringtone/RingtoneHolder.kt b/src/com/android/deskclock/ringtone/RingtoneHolder.kt
new file mode 100644
index 0000000..7ddf6f1
--- /dev/null
+++ b/src/com/android/deskclock/ringtone/RingtoneHolder.kt
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.deskclock.ringtone
+
+import android.net.Uri
+import androidx.recyclerview.widget.RecyclerView.NO_ID
+
+import com.android.deskclock.ItemAdapter.ItemHolder
+import com.android.deskclock.Utils
+import com.android.deskclock.data.DataModel
+
+internal abstract class RingtoneHolder @JvmOverloads constructor(
+ uri: Uri,
+ private val mName: String?,
+ private val mHasPermissions: Boolean = true
+) : ItemHolder<Uri>(uri, NO_ID) {
+ var isSelected = false
+ var isPlaying = false
+
+ val id: Long
+ get() = itemId
+
+ fun hasPermissions(): Boolean {
+ return mHasPermissions
+ }
+
+ val uri: Uri
+ get() = item
+
+ val isSilent: Boolean
+ get() = Utils.RINGTONE_SILENT == uri
+
+ val name: String?
+ get() = mName ?: DataModel.dataModel.getRingtoneTitle(uri)
+}
\ No newline at end of file