parent
e0260de888
commit
92f1800c43
@ -0,0 +1,72 @@ |
|||||||
|
package com.frank.ffmpeg.adapter |
||||||
|
|
||||||
|
import android.view.LayoutInflater |
||||||
|
import android.view.View |
||||||
|
import android.view.ViewGroup |
||||||
|
import android.widget.TextView |
||||||
|
import androidx.recyclerview.widget.RecyclerView |
||||||
|
import com.frank.ffmpeg.R |
||||||
|
import com.frank.ffmpeg.listener.OnItemClickListener |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
/** |
||||||
|
* waterfall layout adapter |
||||||
|
* Created by frank on 2021/9/27. |
||||||
|
*/ |
||||||
|
class WaterfallAdapter() : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
||||||
|
|
||||||
|
companion object { |
||||||
|
const val DEFAULT_MARGIN = 5 |
||||||
|
} |
||||||
|
|
||||||
|
private var itemList: List<String>? = null |
||||||
|
|
||||||
|
private var heightList: ArrayList<Int>? = null |
||||||
|
|
||||||
|
private var onItemClickListener: OnItemClickListener? = null |
||||||
|
|
||||||
|
constructor(itemList: List<String>?) : this() { |
||||||
|
this.itemList = itemList |
||||||
|
|
||||||
|
heightList = arrayListOf(itemList!!.size) |
||||||
|
for (i in itemList.indices) { |
||||||
|
val height = Random().nextInt(20) + DEFAULT_MARGIN |
||||||
|
heightList?.add(height) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fun setOnItemClickListener(onItemClickListener: OnItemClickListener) { |
||||||
|
this.onItemClickListener = onItemClickListener |
||||||
|
} |
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { |
||||||
|
return RandomHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_waterfall ,parent, false)) |
||||||
|
} |
||||||
|
|
||||||
|
override fun getItemCount(): Int { |
||||||
|
return itemList?.size ?: 0 |
||||||
|
} |
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { |
||||||
|
val randomHolder = holder as RandomHolder |
||||||
|
val layoutParams:ViewGroup.MarginLayoutParams = |
||||||
|
randomHolder.txtComponent.layoutParams as ViewGroup.MarginLayoutParams |
||||||
|
var margin = DEFAULT_MARGIN |
||||||
|
if (heightList!![position] > DEFAULT_MARGIN) margin = heightList!![position] |
||||||
|
layoutParams.topMargin = margin |
||||||
|
layoutParams.bottomMargin = margin |
||||||
|
randomHolder.txtComponent.layoutParams = layoutParams |
||||||
|
|
||||||
|
randomHolder.txtComponent.text = itemList!![position] |
||||||
|
if (onItemClickListener != null) { |
||||||
|
randomHolder.txtComponent.setOnClickListener { |
||||||
|
onItemClickListener!!.onItemClick(randomHolder.absoluteAdapterPosition) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private inner class RandomHolder internal constructor(itemView: View) : RecyclerView.ViewHolder(itemView) { |
||||||
|
internal val txtComponent :TextView = itemView.findViewById(R.id.txt_component) |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,89 +1,14 @@ |
|||||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
android:layout_width="match_parent" |
android:layout_width="match_parent" |
||||||
android:layout_height="match_parent"> |
android:layout_height="match_parent" |
||||||
|
android:layout_marginStart="16dp" |
||||||
|
android:layout_marginEnd="16dp"> |
||||||
|
|
||||||
<ScrollView |
<androidx.recyclerview.widget.RecyclerView |
||||||
|
android:id="@+id/list_main_item" |
||||||
android:layout_width="match_parent" |
android:layout_width="match_parent" |
||||||
android:layout_height="match_parent"> |
android:layout_height="wrap_content" |
||||||
<LinearLayout |
android:layout_centerInParent="true" /> |
||||||
android:layout_width="match_parent" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:orientation="vertical" |
|
||||||
android:gravity="center_horizontal"> |
|
||||||
|
|
||||||
<Button |
|
||||||
android:id="@+id/btn_audio" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:layout_marginTop="40dp" |
|
||||||
android:text="@string/audio_handle"/> |
|
||||||
|
|
||||||
<Button |
|
||||||
android:id="@+id/btn_video" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:text="@string/video_handle" |
|
||||||
android:layout_marginTop="10dp" /> |
|
||||||
|
|
||||||
<Button |
|
||||||
android:id="@+id/btn_media" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:text="@string/media_handle" |
|
||||||
android:layout_marginTop="10dp" /> |
|
||||||
|
|
||||||
<Button |
|
||||||
android:id="@+id/btn_play" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:text="@string/media_play" |
|
||||||
android:layout_marginTop="10dp" |
|
||||||
android:visibility="gone"/> |
|
||||||
|
|
||||||
<Button |
|
||||||
android:id="@+id/btn_push" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:text="@string/video_push" |
|
||||||
android:layout_marginTop="10dp" /> |
|
||||||
|
|
||||||
<Button |
|
||||||
android:id="@+id/btn_live" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:text="@string/video_live" |
|
||||||
android:layout_marginTop="10dp" /> |
|
||||||
|
|
||||||
<Button |
|
||||||
android:id="@+id/btn_filter" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:text="@string/video_filter" |
|
||||||
android:layout_marginTop="10dp" /> |
|
||||||
|
|
||||||
<Button |
|
||||||
android:id="@+id/btn_preview" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:text="@string/video_preview" |
|
||||||
android:layout_marginTop="10dp" /> |
|
||||||
|
|
||||||
<Button |
|
||||||
android:id="@+id/btn_probe" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:text="@string/media_probe" |
|
||||||
android:layout_marginTop="10dp" /> |
|
||||||
|
|
||||||
<Button |
|
||||||
android:id="@+id/btn_audio_effect" |
|
||||||
android:layout_width="wrap_content" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:text="@string/audio_effect" |
|
||||||
android:layout_marginTop="10dp" /> |
|
||||||
|
|
||||||
</LinearLayout> |
|
||||||
</ScrollView> |
|
||||||
|
|
||||||
</RelativeLayout> |
</RelativeLayout> |
||||||
|
@ -0,0 +1,18 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:layout_width="wrap_content" android:layout_height="wrap_content"> |
||||||
|
|
||||||
|
<TextView |
||||||
|
android:id="@+id/txt_component" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:textColor="@color/colorPrimary" |
||||||
|
android:textSize="16sp" |
||||||
|
android:gravity="center" |
||||||
|
android:clickable="true" |
||||||
|
android:focusable="true" |
||||||
|
android:paddingStart="10dp" |
||||||
|
android:paddingEnd="10dp" |
||||||
|
android:background="@drawable/btn_rect"/> |
||||||
|
|
||||||
|
</LinearLayout> |
Loading…
Reference in new issue