kotlin conversion

This commit is contained in:
h4h13 2018-11-30 06:36:16 +05:30
parent 8e6ab40d93
commit b2c15ef186
316 changed files with 13055 additions and 22983 deletions

View file

@ -1,127 +0,0 @@
/*
* Copyright (C) 2017. Alexander Bilchuk <a.bilchuk@sandrlab.com>
*
* 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 code.name.monkey.retromusic.views;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SnapHelper;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.ui.adapter.base.MediaEntryViewHolder;
import code.name.monkey.retromusic.util.RetroUtil;
public class MetalRecyclerViewPager extends RecyclerView {
private int itemMargin;
public MetalRecyclerViewPager(Context context) {
super(context);
init(context, null);
}
public MetalRecyclerViewPager(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public MetalRecyclerViewPager(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs);
}
private void init(Context context, @Nullable AttributeSet attrs) {
if (attrs != null) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MetalRecyclerViewPager, 0, 0);
itemMargin = (int) typedArray.getDimension(R.styleable.MetalRecyclerViewPager_itemMargin, 0f);
typedArray.recycle();
}
setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(this);
}
public void setAdapter(Adapter adapter) {
if (MetalAdapter.class.isInstance(adapter)) {
MetalAdapter metalAdapter = (MetalAdapter) adapter;
metalAdapter.setItemMargin(itemMargin);
metalAdapter.updateDisplayMetrics();
} else {
throw new IllegalArgumentException("Only MetalAdapter is allowed here");
}
super.setAdapter(adapter);
}
public static abstract class MetalAdapter<VH extends MetalViewHolder> extends RecyclerView.Adapter<VH> {
private DisplayMetrics metrics;
private int itemMargin;
private int itemWidth;
public MetalAdapter(@NonNull DisplayMetrics metrics) {
this.metrics = metrics;
}
void setItemMargin(int itemMargin) {
this.itemMargin = itemMargin;
}
void updateDisplayMetrics() {
if (RetroUtil.isTablet()) {
itemWidth = (metrics.widthPixels / 2) - itemMargin * 3;
} else {
itemWidth = metrics.widthPixels - itemMargin ;
}
}
@Override
public void onBindViewHolder(@NonNull VH holder, int position) {
int currentItemWidth = itemWidth;
if (position == 0) {
currentItemWidth += itemMargin;
holder.rootLayout.setPadding(0, 0, 0, 0);
} else if (position == getItemCount() - 1) {
currentItemWidth += itemMargin;
holder.rootLayout.setPadding(0, 0, 0, 0);
}
int height = holder.rootLayout.getLayoutParams().height;
holder.rootLayout.setLayoutParams(new ViewGroup.LayoutParams(currentItemWidth, height));
}
}
public static abstract class MetalViewHolder extends MediaEntryViewHolder {
ViewGroup rootLayout;
public MetalViewHolder(View itemView) {
super(itemView);
rootLayout = (ViewGroup) itemView.findViewById(R.id.root_layout);
}
}
}

View file

@ -0,0 +1,86 @@
package code.name.monkey.retromusic.views
import android.content.Context
import android.util.AttributeSet
import android.util.DisplayMetrics
import android.view.View
import android.view.ViewGroup
import androidx.annotation.NonNull
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.PagerSnapHelper
import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.ui.adapter.base.MediaEntryViewHolder
import code.name.monkey.retromusic.util.RetroUtil
class MetalRecyclerViewPager : RecyclerView {
constructor(context: Context) : super(context) {
init(context, null)
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init(context, attrs)
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init(context, attrs)
}
private var itemMargin: Int = 0
fun init(context: Context, attrs: AttributeSet?) {
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.MetalRecyclerViewPager, 0, 0)
itemMargin = typedArray.getDimension(R.styleable.MetalRecyclerViewPager_itemMargin, 0f).toInt()
typedArray.recycle()
layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
val snapHelper = PagerSnapHelper()
snapHelper.attachToRecyclerView(this)
}
override fun setAdapter(adapter: Adapter<*>?) {
if (adapter is MetalAdapter) {
adapter.setItemMargin(itemMargin)
adapter.updateDisplayMetrics()
} else {
throw IllegalArgumentException("Only MetalAdapter is allowed here")
}
super.setAdapter(adapter)
}
abstract class MetalAdapter<VH : MetalViewHolder>(@NonNull val displayMetrics: DisplayMetrics) : RecyclerView.Adapter<VH>() {
private var itemMargin: Int = 0
private var itemWidth: Int = 0
fun setItemMargin(itemMargin: Int) {
this.itemMargin = itemMargin
}
fun updateDisplayMetrics() {
itemWidth = if (RetroUtil.isTablet()) {
displayMetrics.widthPixels / 2 - itemMargin * 3
} else {
displayMetrics.widthPixels - itemMargin
}
}
override fun onBindViewHolder(holder: VH, position: Int) {
var currentItemWidth = itemWidth
if (position == 0) {
currentItemWidth += itemMargin
holder.rootLayout.setPadding(0, 0, 0, 0)
} else if (position == itemCount - 1) {
currentItemWidth += itemMargin
holder.rootLayout.setPadding(0, 0, 0, 0)
}
val height = holder.rootLayout.layoutParams.height
holder.rootLayout.layoutParams = ViewGroup.LayoutParams(currentItemWidth, height)
}
}
abstract class MetalViewHolder(itemView: View) : MediaEntryViewHolder(itemView) {
var rootLayout: ViewGroup = itemView.findViewById(R.id.root_layout)
}
}

View file

@ -1,33 +0,0 @@
package code.name.monkey.retromusic.views;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import code.name.monkey.appthemehelper.ThemeStore;
public class TintIconColorToolbar extends Toolbar {
public TintIconColorToolbar(Context context) {
super(context);
}
public TintIconColorToolbar(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public TintIconColorToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void setNavigationIcon(@Nullable Drawable icon) {
super.setNavigationIcon(icon);
if (icon != null) {
icon.setColorFilter(ThemeStore.accentColor(getContext()), PorterDuff.Mode.SRC_IN);
}
}
}

View file

@ -0,0 +1,22 @@
package code.name.monkey.retromusic.views
import android.content.Context
import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import androidx.appcompat.widget.Toolbar
import code.name.monkey.appthemehelper.ThemeStore
class TintIconColorToolbar : Toolbar {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
override fun setNavigationIcon(icon: Drawable?) {
super.setNavigationIcon(icon)
icon?.setColorFilter(ThemeStore.accentColor(context), PorterDuff.Mode.SRC_IN)
}
}