Coder Social home page Coder Social logo

base-android's Introduction

base-android

Android DataBinding BaseClass 설계

Toolbar (using DataBinding) Example

ToolbarConfiguration

  • BaseObservable를 활용해서 툴바 tiitle, image 값
public class ToolbarConfiguration extends BaseObservable {
    private String title;
    @DrawableRes
    private Integer imageDrawable;
    private View.OnClickListener listener;

    @Bindable
    public String getTitle() {
        return title;
    }

    @Bindable
    public Integer getImageDrawable() {
        return imageDrawable;
    }

    @Bindable
    public View.OnClickListener getListener() {
        return listener;
    }

    public void setConfiguration(String title, Integer imageDrawable, View.OnClickListener listener) {
        this.title = title;
        this.imageDrawable = imageDrawable;
        this.listener = listener;
        notifyChange();
    }
}

Base Toolbar layout (xml)

  • 필요한 xml에 include 이용해서 사용
<?xml version="1.0" encoding="utf-8"?>
<layout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:bind="http://schemas.android.com/apk/res-auto">

    <data>
        <import type="android.view.View"/>

        <variable
                name="config"
                type="com.android.libbase.databinding.configurations.ToolbarConfiguration"/>
    </data>

    <com.hugocastelani.waterfalltoolbar.WaterfallToolbar
            android:id="@+id/waterfall_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize">

        <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/white">
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:textColor="@android:color/black"
                    android:visibility="@{config.title != null || !config.title.isEmpty() ? View.VISIBLE : View.GONE}"
                    android:text="@{config.title}"/>

            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="end|center_vertical"
                    android:layout_marginEnd="10dp"
                    android:background="?android:attr/selectableItemBackgroundBorderless"
                    bind:imgRes="@{config.imageDrawable}"
                    bind:navigationOnClickListener="@{config.listener}"/>
        </androidx.appcompat.widget.Toolbar>

    </com.hugocastelani.waterfalltoolbar.WaterfallToolbar>
</layout>

BaseRecyclerview(using DataBinding) Example

Sample Adapter

  • Multi View Type 처리 가능
  • Endless scroll (load more)
public class GenericRVAdapterTest extends GenericRVAdapter<RVModel, OnRecyclerPositionClickListener> {

    private static final int NEW_TYPE = 4;

    GenericRVAdapterTest(Context context, OnRecyclerPositionClickListener listener) {
        super(context, listener);
    }

    @Override
    public int getItemViewType(int position) {
        if (getItem(position) != null && position % 3 == 0) {
            return NEW_TYPE;
        }
        return super.getItemViewType(position);
    }

    @Override
    protected int getItemLayout(int viewType) {
        if (viewType == NEW_TYPE) {
            return R.layout.rv_item2;
        }
        return R.layout.rv_item;
    }

    @Override
    public void onBindView(ViewDataBinding binding, ItemViewHolder viewHolder, RVModel item, int viewType, @Nullable OnRecyclerPositionClickListener listener) {
        AdapterModel model = (AdapterModel) item;

        if (viewType != NEW_TYPE) {
            RvItemBinding rvItemBinding = (RvItemBinding) binding;
            rvItemBinding.setItem(model);
        }
        else {
            RvItem2Binding rvItem2Binding = (RvItem2Binding) binding;
            rvItem2Binding.setItem(model);
        }
    }
}

MainAcitivy

  mainBinding.recyclerview.setLayoutManager(new LinearLayoutManager(this));
    GenericRVAdapterTest adapter = new GenericRVAdapterTest(getBaseContext(), null);
    adapter.addAll(getItems());
    mainBinding.recyclerview.setAdapter(adapter);

    mainBinding.recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
        }
    });

private List<RVModel> getItems() {
    return Arrays.asList(new AdapterModel("홍길동", "32", "https://t1.daumcdn.net/cfile/tistory/194599374F7049A901"),
            new AdapterModel("김철수", "50", "https://t1.daumcdn.net/cfile/tistory/194599374F7049A901"),
            new AdapterModel("안길영", "15", "https://t1.daumcdn.net/cfile/tistory/194599374F7049A901"),
            new AdapterModel("Ailee","25", "https://t1.daumcdn.net/cfile/tistory/194599374F7049A901"),
            new AdapterModel("asd","25", "https://t1.daumcdn.net/cfile/tistory/194599374F7049A901"),
            new AdapterModel("314","25", "https://t1.daumcdn.net/cfile/tistory/194599374F7049A901"),
            new AdapterModel("adsvv","25", "https://t1.daumcdn.net/cfile/tistory/194599374F7049A901"),
            new AdapterModel("cccc","25", "https://t1.daumcdn.net/cfile/tistory/194599374F7049A901"),
            new AdapterModel("qqqq","25", "https://t1.daumcdn.net/cfile/tistory/194599374F7049A901"),
            new AdapterModel("rr","25", "https://t1.daumcdn.net/cfile/tistory/194599374F7049A901"),
            new AdapterModel("ee","25", "https://t1.daumcdn.net/cfile/tistory/194599374F7049A901"),
            new AdapterModel("34f33","25", "https://t1.daumcdn.net/cfile/tistory/194599374F7049A901"));
}

base-android's People

Contributors

ykw93 avatar

Watchers

 avatar

base-android's Issues

Base Recyclerview Adapter 이슈

기존에 Base Recyclerview Adapter 안에 endless scroll 기능이 있었는데 문제점이 있어 제거 필요

문제점

  • 각각의 어댑터가 무거워짐.
  • base adapter에 있는 getProgressLayout을 자식 어댑터에서 구현해야 되는 문제
  • 여러개의 뷰타입 사용 시 각각의 뷰타입의 width가 동일하게 나오는 문제
    예를 들어 1번 뷰타입은 match_parent이고 2번 뷰타입은 width가 110dp 인데 각각 적용 되지 않고 전부 mathc_parent로 적용 되는 문제

Endless Recyclerview

기존에 Recyclerview base adapter에 있는 Endless loading 기능을 제거 했으므로
Endless 기능을 이용할 수 있는 Custom Recyclerview 추가 필요

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.