parent
6417f31767
commit
d705a85690
@ -0,0 +1,117 @@ |
||||
package com.keylesspalace.tusky.adapter |
||||
|
||||
import android.graphics.drawable.Drawable |
||||
import android.util.Log |
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import android.widget.FrameLayout |
||||
import android.widget.ImageView |
||||
import androidx.appcompat.widget.AppCompatImageButton |
||||
import androidx.recyclerview.widget.GridLayoutManager |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import com.bumptech.glide.Glide |
||||
import com.bumptech.glide.request.target.CustomTarget |
||||
import com.bumptech.glide.request.transition.Transition |
||||
import com.google.android.material.tabs.TabLayout |
||||
import com.google.android.material.tabs.TabLayoutMediator.TabConfigurationStrategy |
||||
import com.keylesspalace.tusky.R |
||||
import com.keylesspalace.tusky.entity.StickerPack |
||||
import com.keylesspalace.tusky.view.EmojiKeyboard |
||||
import com.keylesspalace.tusky.view.EmojiKeyboard.EmojiKeyboardAdapter |
||||
import java.util.* |
||||
|
||||
class StickerAdapter( |
||||
private val stickerPacks: Array<StickerPack>, |
||||
private val listener: EmojiKeyboard.OnEmojiSelectedListener |
||||
) : RecyclerView.Adapter<SingleViewHolder>(), TabConfigurationStrategy, EmojiKeyboardAdapter { |
||||
|
||||
private val recentsAdapter = StickerPageAdapter(null, listener, emptyList()) |
||||
// this value doesn't reflect actual button width but how much we want for button to take space |
||||
// this is bad, only villains do that |
||||
private val BUTTON_WIDTH_DP = 90.0f |
||||
|
||||
override fun onConfigureTab(tab: TabLayout.Tab, position: Int) { |
||||
if (position == 0) { |
||||
tab.setIcon(R.drawable.ic_access_time) |
||||
return |
||||
} |
||||
|
||||
val pack = stickerPacks[position - 1] |
||||
val imageView = ImageView(tab.view.context) |
||||
imageView.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.MATCH_PARENT) |
||||
Glide.with(imageView) |
||||
.asDrawable() |
||||
.load(pack.internal_url + pack.tabIcon) |
||||
.thumbnail() |
||||
.centerCrop() |
||||
.into( object: CustomTarget<Drawable>() { |
||||
override fun onLoadCleared(placeholder: Drawable?) { |
||||
} |
||||
|
||||
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) { |
||||
// tab.icon = resource |
||||
imageView.setImageDrawable(resource) |
||||
tab.customView = imageView |
||||
} |
||||
}) |
||||
} |
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SingleViewHolder { |
||||
val view = LayoutInflater.from(parent.context) |
||||
.inflate(R.layout.item_emoji_keyboard_page, parent, false) |
||||
val holder = SingleViewHolder(view) |
||||
|
||||
val dm = parent.context.resources.displayMetrics |
||||
val wdp = dm.widthPixels / dm.density |
||||
val rows = (wdp / BUTTON_WIDTH_DP + 0.5).toInt() |
||||
|
||||
(view as RecyclerView).layoutManager = GridLayoutManager(view.getContext(), rows) |
||||
return holder |
||||
} |
||||
|
||||
override fun getItemCount(): Int { |
||||
return stickerPacks.size + 1 |
||||
} |
||||
|
||||
override fun onRecentsUpdate(set: MutableSet<String>) { |
||||
val list = set.toMutableList() |
||||
list.reverse() |
||||
recentsAdapter.stickers = list |
||||
recentsAdapter.notifyDataSetChanged() |
||||
} |
||||
|
||||
override fun onBindViewHolder(holder: SingleViewHolder, position: Int) { |
||||
if( position == 0 ) { |
||||
(holder.itemView as RecyclerView).adapter = recentsAdapter |
||||
} else { |
||||
val pack = stickerPacks[position - 1] |
||||
(holder.itemView as RecyclerView).adapter = StickerPageAdapter(pack.internal_url, listener, pack.stickers) |
||||
} |
||||
} |
||||
|
||||
private class StickerPageAdapter( |
||||
private val url: String?, |
||||
var listener: EmojiKeyboard.OnEmojiSelectedListener, |
||||
var stickers: List<String> |
||||
) : RecyclerView.Adapter<SingleViewHolder>() { |
||||
override fun getItemCount(): Int { |
||||
return stickers.size |
||||
} |
||||
|
||||
override fun onBindViewHolder(holder: SingleViewHolder, position: Int) { |
||||
(holder.itemView as AppCompatImageButton).setOnClickListener { |
||||
listener.onEmojiSelected("", ( url ?: "" ) + stickers[position]) |
||||
} |
||||
Glide.with(holder.itemView) |
||||
.load(( url ?: "" ) + stickers[position]) |
||||
.thumbnail() |
||||
.into(holder.itemView) |
||||
} |
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SingleViewHolder { |
||||
val view = LayoutInflater.from(parent.context) |
||||
.inflate(R.layout.item_emoji_keyboard_sticker, parent, false) |
||||
return SingleViewHolder(view) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,27 @@ |
||||
/* Copyright 2018 Conny Duck |
||||
* |
||||
* This file is a part of Tusky. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the |
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
||||
* Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not, |
||||
* see <http://www.gnu.org/licenses>. */ |
||||
|
||||
package com.keylesspalace.tusky.entity |
||||
|
||||
import android.os.Parcelable |
||||
import kotlinx.android.parcel.Parcelize |
||||
|
||||
@Parcelize |
||||
data class StickerPack( |
||||
val title: String, |
||||
val tabIcon: String, |
||||
val stickers: List<String>, |
||||
var internal_url: String = "" |
||||
) : Parcelable |
@ -0,0 +1,16 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:viewportWidth="24" |
||||
android:viewportHeight="24"> |
||||
<path |
||||
android:pathData="m17.6395,2.4501c-0.1153,-0.0029 -0.237,0.0011 -0.3594,0.0098L6.5086,2.4599C4.1934,2.3957 2.2618,4.5 2.4696,6.7919l-0.0019,-0.0566c0.0029,3.6483 -0.0044,7.2998 0.0059,10.9512a0.6173,0.6173 0,0 0,0 0.0137c0.0585,2.2386 2.115,4.0322 4.332,3.8359L6.7508,21.538h5.1055,0.25a0.6173,0.6173 0,0 0,0.4375 -0.1816l0.25,-0.252 8.2891,-8.3203L21.3661,12.499a0.6173,0.6173 0,0 0,0.1797 -0.4355v-0.2148c0.0001,-1.8499 -0,-3.7001 -0.0039,-5.5508a0.6173,0.6173 0,0 0,0 -0.0137C21.4874,4.1928 19.6863,2.5008 17.6395,2.4501ZM12.0965,4.6923c1.8296,-0.0016 3.6576,0.0006 5.4844,0.0156 1.0144,0.0827 1.8488,1.1605 1.7344,2.1738a0.6173,0.6173 0,0 0,-0.0039 0.0684v4.2813h-5.582c-0.3422,0 -0.6713,0.0707 -0.9688,0.1973 -0.2971,0.1265 -0.5637,0.3098 -0.7891,0.5352 -0.2254,0.2254 -0.4087,0.4919 -0.5352,0.7891 -0.1266,0.2975 -0.1973,0.6266 -0.1973,0.9688v5.5801C9.7736,19.3008 8.3092,19.2993 6.8446,19.29 5.6148,19.2409 4.5685,17.9653 4.6981,16.7431a0.6173,0.6173 0,0 0,0.0039 -0.0625c0.0084,-3.4464 -0.0156,-6.8869 0.0137,-10.3223 0.0799,-0.8927 0.9478,-1.6796 1.8438,-1.6641a0.6173,0.6173 0,0 0,0.0078 0c1.8438,0.0043 3.6879,-0.0004 5.5293,-0.0019zM14.1629,13.4658h1.1934,1.8906l-3.7734,3.7891v-1.9063,-1.1934c0,-0.094 0.0201,-0.1843 0.0547,-0.2656 0.0341,-0.0801 0.0831,-0.1554 0.1484,-0.2207 0.0654,-0.0654 0.1406,-0.1144 0.2207,-0.1484 0.0813,-0.0346 0.1716,-0.0547 0.2656,-0.0547z" |
||||
android:strokeAlpha="1" |
||||
android:strokeLineJoin="miter" |
||||
android:strokeWidth="1" |
||||
android:fillColor="#000000" |
||||
android:strokeColor="#00000000" |
||||
android:fillType="nonZero" |
||||
android:fillAlpha="1" |
||||
android:strokeLineCap="square"/> |
||||
</vector> |
@ -0,0 +1,12 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.appcompat.widget.AppCompatImageButton |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="80dp" |
||||
android:layout_height="80dp" |
||||
android:layout_marginRight="0dp" |
||||
android:layout_marginBottom="0dp" |
||||
android:layout_marginLeft="0dp" |
||||
android:layout_marginTop="0dp" |
||||
android:background="@null" |
||||
android:minWidth="0dp" |
||||
/> |
Loading…
Reference in new issue