Skip to content

Commit

Permalink
add ui-adapters module v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
teebbo committed Jun 23, 2019
1 parent 54e4cb7 commit 360b54d
Show file tree
Hide file tree
Showing 17 changed files with 357 additions and 4 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions androidx-deps.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
*
* 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.
*/

ext.deps = [:]

deps.android_gradle_plugin = "com.android.tools.build:gradle:3.4.0"
deps.androidx_test_runner = "androidx.test:runner:1.2.0"

def build_versions = [:]
build_versions.min_sdk = 15
build_versions.target_sdk = 28
build_versions.build_tools = "28.0.3"
ext.build_versions = build_versions

// androidx
def androidx = [:]

androidx.appcompat = "androidx.appcompat:appcompat:1.0.2"
androidx.googlematerial = "com.google.android.material:material:1.0.0"
androidx.annotation = "androidx.annotation:annotation:1.0.0"
androidx.cardview = "androidx.cardview:cardview:1.0.0"
androidx.drawerlayout = "androidx.drawerlayout:drawerlayout:1.0.0"
androidx.coordinatorlayout = "androidx.coordinatorlayout:coordinatorlayout:1.0.0"
androidx.constraintlayout = "androidx.constraintlayout:constraintlayout:1.1.3"
androidx.recyclerview = "androidx.recyclerview:recyclerview:1.0.0"
androidx.vectordrawable = 'androidx.vectordrawable:vectordrawable:1.0.0'

def espresso = [:]
espresso.core = "androidx.test.espresso:espresso-core:3.2.0"

deps.androidx = androidx
deps.espresso = espresso

ext.deps = deps
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

buildscript {

apply from: 'versions.gradle'
apply from: 'androidx-deps.gradle'
apply from: 'dependencies.gradle'

dependencies {
classpath deps.android_gradle_plugin
classpath deps.android_maven_gradle_plugin
Expand Down
4 changes: 2 additions & 2 deletions commons/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'java-library'
apply plugin: 'maven'

group=toolbox.group
version=toolbox.commons_version
/*group=toolbox.group
version=toolbox.commons_version*/

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
43 changes: 43 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
*
* 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.
*/


def toolbox = [:]
toolbox.version_code = 1
toolbox.version_name = "0.1.0"
toolbox.commons_version = "rc0.1.1"
toolbox.android_version = "rc0.1.0"
toolbox.group = "com.github.aleengo.peachbox"
toolbox.artifact = "peank"
toolbox.description = "Personal dev tools for Android"
ext.toolbox = toolbox


deps.android_maven_gradle_plugin = "com.github.dcendents:android-maven-gradle-plugin:2.1"

deps.junit = "junit:junit:4.12"
deps.lombok = "org.projectlombok:lombok:1.16.20"
deps.gson = "com.google.code.gson:gson:2.8.5"

def butterknife = [:]
butterknife.runtime = "com.jakewharton:butterknife:10.0.0"
butterknife.compiler = "com.jakewharton:butterknife-compiler:10.0.0"
deps.butterknife = butterknife

def okhttp = [:]
okhttp.runtime = "com.squareup.okhttp3:okhttp:3.12.0"
deps.okhttp = okhttp

ext.deps = deps
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':box', ':commons', ':peach'
include ':box', ':commons', ':peach', ':ui-adapters'
1 change: 1 addition & 0 deletions ui-adapters/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions ui-adapters/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28


defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

compileOnly deps.lombok
annotationProcessor deps.lombok

implementation deps.androidx.appcompat
implementation deps.androidx.recyclerview

testImplementation deps.junit
androidTestImplementation deps.androidx_test_runner
androidTestImplementation deps.espresso.core
}
21 changes: 21 additions & 0 deletions ui-adapters/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.aleengo.peank.uiadapter;

import android.content.Context;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.aleengo.peank.uiadapter.test", appContext.getPackageName());
}
}
2 changes: 2 additions & 0 deletions ui-adapters/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aleengo.peank.uiadapter" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.aleengo.peank.uiadapter.listview;

/**
* Copyright Aleengo 2019. All rights reserved.
* Created by bau.cj on 22/06/2019.
*/
public abstract class AdapterListView {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.aleengo.peank.uiadapter.recyclerview;


import java.util.Collection;

/**
* Copyright Aleengo 2019. All rights reserved.
* Created by bau.cj on 22/06/2019.
*/
public interface AdapterContract<E> {

void clear();
E getItem(int position);
void addItem(E item);
void addItem(int position, E item);
void removeItem(int position);
void updateItem(int position , E item);
void addItems(Collection<E> collection);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.aleengo.peank.uiadapter.recyclerview;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import lombok.Getter;

/**
* Copyright Aleengo 2019. All rights reserved.
* Created by bau.cj on 22/06/2019.
*/
public abstract class AdapterRecyclerView<E, ITEMVIEW extends ItemView<E>>
extends RecyclerView.Adapter<AdapterRecyclerView.ViewHolder>
implements AdapterContract<E> {

@Getter
private Context context;
private final List<E> items;

public AdapterRecyclerView(Context context) {
this.context = context;
this.items = new LinkedList<>();
}

@NonNull
@Override
public AdapterRecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
final ITEMVIEW itemview = onCreateItemView(parent, viewType);
return new ViewHolder(itemview);
}

public abstract ITEMVIEW onCreateItemView(ViewGroup parent, int viewType);

@Override
public int getItemCount() {
return items.size();
}

@Override
public E getItem(int position) {
return items.get(position);
}

@Override
public void clear() {
final int oldSize = getItemCount();
items.clear();
notifyItemRangeChanged(getItemCount(), oldSize);
}

@Override
public void addItem(E item) {
items.add(item);
notifyItemInserted(getItemCount() - 1);
}

@Override
public void addItem(int position, E item) {
items.add(position, item);
notifyItemInserted(position);
}

@Override
public void removeItem(int position) {
items.remove(position);
notifyItemRemoved(position);
}

@Override
public void updateItem(int position, E item) {
items.set(position, item);
notifyItemChanged(position);
}

@Override
public void addItems(Collection<E> newItems) {
final int oldSize = getItemCount();
items.addAll(newItems);
notifyItemRangeChanged(oldSize, newItems.size());
}

public static class ViewHolder extends RecyclerView.ViewHolder {

@Getter
private View itemView;

public ViewHolder(@NonNull View itemView) {
super(itemView);
this.itemView = itemView;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.aleengo.peank.uiadapter.recyclerview;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;


/**
* Copyright Aleengo 2019. All rights reserved.
* Created by bau.cj on 22/06/2019.
*/

public abstract class ItemView<E> extends FrameLayout {

public ItemView(Context context) {
this(context, null);
}

public ItemView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public abstract void bind(E item, int position);
}
3 changes: 3 additions & 0 deletions ui-adapters/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">UiAdapters</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.aleengo.peank.uiadapter;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}

0 comments on commit 360b54d

Please sign in to comment.