Skip to content

Commit

Permalink
retrofit & room code moved into a reusable library module.
Browse files Browse the repository at this point in the history
  • Loading branch information
syslogic committed Aug 5, 2023
1 parent b14b4f3 commit 5d5e1d0
Show file tree
Hide file tree
Showing 76 changed files with 425 additions and 174 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ buildscript {
test_rules_version = '1.5.0'
uiautomator_version = '2.2.0'
espresso_version = '3.5.1'

version_name = '1.1.5'
}
}

plugins {
id 'com.android.application' version "$agp_version" apply false
id 'com.android.library' version "$agp_version" apply false
id 'androidx.navigation.safeargs' version "$nav_version" apply false
}

Expand Down
1 change: 1 addition & 0 deletions library/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
172 changes: 172 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
plugins {
id 'com.android.library'
id 'maven-publish'
}

android {
namespace 'io.syslogic.github.api'
compileSdk 34

defaultConfig {
minSdk 22
targetSdk 34
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

buildFeatures {
buildConfig true
dataBinding true
}

buildTypes {
debug {
// it breaks the data-binding, eg. when running ./gradlew :library:publishToMavenLocal
testCoverageEnabled false
minifyEnabled false
}
release {
minifyEnabled false
}
}

lint {
lintConfig rootProject.file('lint.xml')
checkAllWarnings true
warningsAsErrors true
abortOnError false
showAll false
}

publishing {
singleVariant('release') {
withSourcesJar()
withJavadocJar()
}
}
}

dependencies {

// Annotations
implementation "androidx.annotation:annotation:$annotation_version"

// Material Design Components
implementation "com.google.android.material:material:$material_version"

// App Compat
implementation "androidx.appcompat:appcompat:$appcompat_version"

// Data-Binding Runtime
implementation "androidx.databinding:databinding-runtime:$agp_version"

// Room Runtime
annotationProcessor "androidx.room:room-compiler:$room_version"
testImplementation "androidx.room:room-testing:$room_version"
implementation "androidx.room:room-runtime:$room_version"

// Retrofit2
implementation "com.google.code.gson:gson:$gson_version"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation ("com.squareup.retrofit2:converter-gson:$retrofit_version") {
exclude group: "com.google.code.gson", module: "gson"
}

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
}

tasks.register('javadoc', Javadoc) {

title = "GitHub API Client ${android.defaultConfig.versionName}"
source = android.sourceSets.main.java.srcDirs
destinationDir = file("${project.buildDir}/outputs/javadoc/")
configurations.implementation.setCanBeResolved(true)
classpath = files(new File("${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"))
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += fileTree(dir: "$buildDir/tmp/aarsToJars/")
classpath += configurations.implementation
exclude "**/BuildConfig.java", "**/R.java"
failOnError false

// options.verbose()
// javadoc: warning - The code being documented uses modules but the packages
// defined in https://developer.android.com/reference/ are in the unnamed module.
options.links "https://docs.oracle.com/en/java/javase/17/docs/api/"
options.linksOffline "https://developer.android.com/reference", "${android.sdkDirectory}/docs/reference"
options.linkSource true
options.author true

doFirst {

// extract AAR files
configurations.implementation.filter { it.name.endsWith('.aar') }.each { aar ->
copy {
from zipTree(aar)
include "**/classes.jar"
into "$buildDir/tmp/aarsToJars/${aar.name.replace('.aar', '')}/"
}
}

// provide JAR, which contains the generated data-binding classes
def aar_main = new File("$buildDir/intermediates/aar_main_jar")
if (aar_main.exists()) {
copy {
from aar_main
include "**/classes.jar"
into "$buildDir/tmp/aarsToJars/aar_main_jar/"
}
}
}
}

javadoc.onlyIf {
new File("$buildDir/intermediates/aar_main_jar").exists()
}

tasks.register('javadocJar', Jar) {
dependsOn javadoc
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}

tasks.register('sourcesJar', Jar) {
from android.sourceSets.main.java.srcDirs
archiveClassifier.set('sources')
}

artifacts {
archives javadocJar
archives sourcesJar
}

group = 'io.syslogic'
version = version_name

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId = group
artifactId = 'github-retrofit2-client'
from components.getByName('release')
version = version_name
pom {
name = 'GitHub API Client'
description = 'A simple client library for Android'
url = "https://github.com/syslogic/${artifactId}"
scm {
connection = "scm:git:git://github.com/syslogic/${artifactId}.git"
developerConnection = "scm:git:ssh://github.com/syslogic/${artifactId}.git"
url = "https://github.com/syslogic/${artifactId}/"
}
}
}
}
}
}
Empty file added library/consumer-rules.pro
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.syslogic.github.api;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.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.getInstrumentation().getTargetContext();
assertEquals("io.syslogic.github.api.test", appContext.getPackageName());
}
}
4 changes: 4 additions & 0 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
19 changes: 19 additions & 0 deletions library/src/main/java/io/syslogic/github/api/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.syslogic.github.api;

import androidx.annotation.NonNull;

/**
* Common Constants
*
* @author Martin Zeitler
*/
public final class Constants {
@NonNull public static final String GITHUB_API_BASE_URL = "https://api.github.com/";
@NonNull public static final String GITHUB_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";

/** Table Names */
@NonNull public static final String TABLE_QUERY_STRINGS = "query_strings";
@NonNull public static final String TABLE_REPOSITORIES = "repositories";
@NonNull public static final String TABLE_LICENSES = "licenses";
@NonNull public static final String TABLE_OWNERS = "owners";
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package io.syslogic.github.retrofit;
package io.syslogic.github.api;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.ArrayList;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import io.syslogic.github.Constants;
import io.syslogic.github.model.Branch;
import io.syslogic.github.model.RateLimits;
import io.syslogic.github.model.RepositorySearch;
import io.syslogic.github.model.Repository;
import io.syslogic.github.model.User;
import io.syslogic.github.model.WorkflowsResponse;

import io.syslogic.github.api.model.Branch;
import io.syslogic.github.api.model.RateLimits;
import io.syslogic.github.api.model.Repository;
import io.syslogic.github.api.model.RepositorySearch;
import io.syslogic.github.api.model.User;
import io.syslogic.github.api.model.WorkflowsResponse;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;

import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package io.syslogic.github.retrofit;

import java.util.ArrayList;
package io.syslogic.github.api;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import io.syslogic.github.model.Branch;
import io.syslogic.github.model.RateLimits;
import io.syslogic.github.model.RepositorySearch;
import io.syslogic.github.model.Repository;
import io.syslogic.github.model.User;
import io.syslogic.github.model.WorkflowJobs;
import io.syslogic.github.model.WorkflowsResponse;
import java.util.ArrayList;

import io.syslogic.github.api.model.Branch;
import io.syslogic.github.api.model.RateLimits;
import io.syslogic.github.api.model.Repository;
import io.syslogic.github.api.model.RepositorySearch;
import io.syslogic.github.api.model.User;
import io.syslogic.github.api.model.WorkflowJobs;
import io.syslogic.github.api.model.WorkflowsResponse;
import okhttp3.ResponseBody;

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.HEAD;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.syslogic.github.adapter;
package io.syslogic.github.api.adapter;

import android.content.Context;
import android.content.res.Resources;
Expand All @@ -12,7 +12,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

import io.syslogic.github.model.SpinnerItem;
import io.syslogic.github.api.model.SpinnerItem;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -28,7 +28,7 @@ abstract public class BaseArrayAdapter extends BaseAdapter {

@NonNull protected ArrayList<SpinnerItem> mItems = new ArrayList<>();

BaseArrayAdapter(@NonNull Context context) {
protected BaseArrayAdapter(@NonNull Context context) {
this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

Expand Down Expand Up @@ -61,7 +61,7 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
return convertView;
}

void setItems(@NonNull Context context, @NonNull @ArrayRes Integer arrayKeys, @NonNull @ArrayRes Integer arrayValues) {
protected void setItems(@NonNull Context context, @NonNull @ArrayRes Integer arrayKeys, @NonNull @ArrayRes Integer arrayValues) {
this.clearItems();
Resources res = context.getResources();
String[] keys = res.getStringArray(arrayKeys);
Expand All @@ -77,7 +77,7 @@ void setItems(List<SpinnerItem> items) {
this.mItems.addAll(items);
}

void clearItems() {
protected void clearItems() {
this.mItems.clear();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.syslogic.github.content;
package io.syslogic.github.api.content;

import android.content.ContentProvider;
import android.content.ContentValues;

import androidx.annotation.NonNull;

import io.syslogic.github.model.BaseModel;
import io.syslogic.github.api.model.BaseModel;

/**
* Model Interface for {@link ContentProvider} items.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.syslogic.github.model;

import java.io.Serializable;
package io.syslogic.github.api.model;

import androidx.databinding.BaseObservable;

import java.io.Serializable;

/**
* Base Model
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.syslogic.github.model;

import com.google.gson.annotations.SerializedName;
package io.syslogic.github.api.model;

import androidx.annotation.NonNull;

import com.google.gson.annotations.SerializedName;

/**
* Model: Branch
*
Expand Down
Loading

0 comments on commit 5d5e1d0

Please sign in to comment.