Tab bar and stuff

This commit is contained in:
Grishka
2022-02-03 11:01:34 +03:00
parent a1dee1fc88
commit 20d3a62747
25 changed files with 364 additions and 22 deletions

View File

@@ -0,0 +1,55 @@
package org.joinmastodon.android.ui.views;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import org.joinmastodon.android.R;
import java.util.function.IntConsumer;
import androidx.annotation.IdRes;
public class TabBar extends LinearLayout{
@IdRes
private int selectedTabID;
private IntConsumer listener;
public TabBar(Context context){
this(context, null);
}
public TabBar(Context context, AttributeSet attrs){
this(context, attrs, 0);
}
public TabBar(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
}
@Override
public void onViewAdded(View child){
super.onViewAdded(child);
if(child.getId()!=0){
if(selectedTabID==0){
selectedTabID=child.getId();
child.setSelected(true);
}
child.setOnClickListener(this::onChildClick);
}
}
private void onChildClick(View v){
if(v.getId()==selectedTabID)
return;
findViewById(selectedTabID).setSelected(false);
v.setSelected(true);
selectedTabID=v.getId();
listener.accept(selectedTabID);
}
public void setListener(IntConsumer listener){
this.listener=listener;
}
}