1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.deskclock.ringtone 18 19 import android.view.LayoutInflater 20 import android.view.View 21 import android.view.ViewGroup 22 import android.widget.ImageView 23 import android.widget.TextView 24 25 import com.android.deskclock.ItemAdapter.ItemViewHolder 26 import com.android.deskclock.R 27 28 internal class AddCustomRingtoneViewHolder private constructor(itemView: View) 29 : ItemViewHolder<AddCustomRingtoneHolder>(itemView), View.OnClickListener { 30 31 init { 32 itemView.setOnClickListener(this) 33 val selectedView = itemView.findViewById<View>(R.id.sound_image_selected) 34 selectedView.visibility = View.GONE 35 val nameView = itemView.findViewById<View>(R.id.ringtone_name) as TextView 36 nameView.text = itemView.context.getString(R.string.add_new_sound) 37 nameView.alpha = 0.63f 38 val imageView = itemView.findViewById<View>(R.id.ringtone_image) as ImageView 39 imageView.setImageResource(R.drawable.ic_add_white_24dp) 40 imageView.alpha = 0.63f 41 } 42 onClicknull43 override fun onClick(view: View) { 44 notifyItemClicked(CLICK_ADD_NEW) 45 } 46 47 class Factory internal constructor(private val mInflater: LayoutInflater) 48 : ItemViewHolder.Factory { createViewHoldernull49 override fun createViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder<*> { 50 val itemView = 51 mInflater.inflate(R.layout.ringtone_item_sound, parent, false) 52 return AddCustomRingtoneViewHolder(itemView) 53 } 54 } 55 56 companion object { 57 const val VIEW_TYPE_ADD_NEW = Int.MIN_VALUE 58 const val CLICK_ADD_NEW = VIEW_TYPE_ADD_NEW 59 } 60 }