refactored view holders
This commit is contained in:
parent
5d4c600392
commit
27e1f18260
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.view.holder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
public final class CheckableTwoLineWithIconViewHolder extends TwoLineWithIconViewHolder {
|
||||
|
||||
public final CheckBox checkbox;
|
||||
|
||||
public CheckableTwoLineWithIconViewHolder(final View view) {
|
||||
super(view);
|
||||
checkbox = (CheckBox) findViewById(android.R.id.checkbox);
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package org.mariotaku.twidere.view.holder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/3/18.
|
||||
*/
|
||||
public class EmptyViewHolder extends RecyclerView.ViewHolder {
|
||||
public EmptyViewHolder(View view) {
|
||||
super(view);
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@
|
|||
package org.mariotaku.twidere.view.holder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -27,11 +28,13 @@ public class TwoLineWithIconViewHolder extends ViewListHolder {
|
|||
|
||||
public final ImageView icon;
|
||||
public final TextView text1, text2;
|
||||
public final CheckBox checkbox;
|
||||
|
||||
public TwoLineWithIconViewHolder(final View view) {
|
||||
super(view);
|
||||
icon = (ImageView) findViewById(android.R.id.icon);
|
||||
text1 = (TextView) findViewById(android.R.id.text1);
|
||||
text2 = (TextView) findViewById(android.R.id.text2);
|
||||
checkbox = (CheckBox) findViewById(android.R.id.checkbox);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,7 @@ package org.mariotaku.twidere.view.holder;
|
|||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import org.mariotaku.twidere.Constants;
|
||||
|
||||
public class ViewListHolder implements Constants {
|
||||
public class ViewListHolder {
|
||||
|
||||
public View view;
|
||||
|
||||
|
|
|
@ -23,11 +23,10 @@ import android.content.Context
|
|||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.loader.ExtensionsListLoader.ExtensionInfo
|
||||
import org.mariotaku.twidere.util.PermissionsManager
|
||||
import org.mariotaku.twidere.view.holder.CheckableTwoLineWithIconViewHolder
|
||||
import org.mariotaku.twidere.view.holder.TwoLineWithIconViewHolder
|
||||
|
||||
class ExtensionsAdapter(context: Context) : ArrayAdapter<ExtensionInfo>(context, R.layout.list_item_two_line) {
|
||||
|
||||
|
@ -44,12 +43,12 @@ class ExtensionsAdapter(context: Context) : ArrayAdapter<ExtensionInfo>(context,
|
|||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val view = super.getView(position, convertView, parent)
|
||||
|
||||
val holder: CheckableTwoLineWithIconViewHolder
|
||||
val holder: TwoLineWithIconViewHolder
|
||||
val tag = view.tag
|
||||
if (tag is CheckableTwoLineWithIconViewHolder) {
|
||||
if (tag is TwoLineWithIconViewHolder) {
|
||||
holder = tag
|
||||
} else {
|
||||
holder = CheckableTwoLineWithIconViewHolder(view)
|
||||
holder = TwoLineWithIconViewHolder(view)
|
||||
view.tag = holder
|
||||
}
|
||||
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package org.mariotaku.twidere.util
|
||||
|
||||
import android.view.View
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
import org.mariotaku.twidere.view.holder.TwoLineWithIconViewHolder
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2016/12/1.
|
||||
*/
|
||||
|
||||
fun TwoLineWithIconViewHolder.display(
|
||||
user: ParcelableUser,
|
||||
mediaLoader: MediaLoaderWrapper,
|
||||
userColorNameManager: UserColorNameManager,
|
||||
displayProfileImage: Boolean
|
||||
) {
|
||||
text1.setCompoundDrawablesWithIntrinsicBounds(0, 0,
|
||||
Utils.getUserTypeIconRes(user.is_verified, user.is_protected), 0)
|
||||
text1.text = userColorNameManager.getUserNickname(user.key, user.name)
|
||||
text2.text = String.format("@%s", user.screen_name)
|
||||
icon.visibility = if (displayProfileImage) View.VISIBLE else View.GONE
|
||||
if (displayProfileImage) {
|
||||
mediaLoader.displayProfileImage(icon, user)
|
||||
} else {
|
||||
mediaLoader.cancelDisplayTask(icon)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package org.mariotaku.twidere.view.holder
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/3/18.
|
||||
*/
|
||||
class EmptyViewHolder(view: View) : RecyclerView.ViewHolder(view)
|
Loading…
Reference in New Issue