Skip to content

Commit

Permalink
Migrated to AndroidX.
Browse files Browse the repository at this point in the history
Migrated to the official Volley repository.
Added allHeaders information to the NetworkResponse object.
Minor clean up.
  • Loading branch information
SpartanJ committed Feb 8, 2020
1 parent 815c763 commit 50242a9
Show file tree
Hide file tree
Showing 22 changed files with 155 additions and 42 deletions.
1 change: 1 addition & 0 deletions app-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ android {
}

dependencies {
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
api project( ':restafari' )
}
5 changes: 4 additions & 1 deletion app-test/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.ensoft.restafari_app" >

<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -10,7 +11,9 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".example.App">
android:name=".example.App"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">

<activity android:name=".example.IpHistoryActivity" >
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
Expand Down
4 changes: 2 additions & 2 deletions app-test/src/main/res/layout/activity_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">

<android.support.v4.widget.SwipeRefreshLayout
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand All @@ -20,6 +20,6 @@
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>

</android.support.v4.widget.SwipeRefreshLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

</RelativeLayout>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
}
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true
16 changes: 8 additions & 8 deletions restafari/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
apply plugin: 'com.android.library'

def versionMajor = 0
def versionMinor = 3
def versionPatch = 40
def versionMinor = 4
def versionPatch = 0

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
compileSdkVersion 29
buildToolsVersion '29.0.0'

defaultConfig {
minSdkVersion 14
targetSdkVersion 28
targetSdkVersion 29
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
}
Expand All @@ -27,9 +27,9 @@ android {
}

dependencies {
api 'com.android.support:appcompat-v7:28.0.0'
api 'com.google.code.gson:gson:2.8.2'
api 'com.mcxiaoke.volley:library:1.0.19'
api 'androidx.appcompat:appcompat:1.1.0'
api 'com.google.code.gson:gson:2.8.5'
api 'com.android.volley:volley:1.1.1'
}

ext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.provider.BaseColumns;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;

import java.util.Arrays;

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

public class DatabaseProvider extends ContentProvider
{
public static String AUTHORITY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.database.Cursor;
import android.net.Uri;
import android.provider.BaseColumns;
import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.ensoft.restafari.helper.ReflectionHelper;
Expand All @@ -14,6 +13,8 @@
import java.util.Arrays;
import java.util.List;

import androidx.annotation.Nullable;

public class DatabaseTableModel<T extends DatabaseModel> extends DatabaseTable
{
protected Class<? extends DatabaseModel> clazz;
Expand Down Expand Up @@ -340,19 +341,19 @@ public CursorLoader getLoaderFromId( long id )
return new CursorLoader( getContext(), getRowContentUri( id ), tableColumns.getAll(), null, null, null );
}

public android.support.v4.content.CursorLoader getAllSupportLoader( @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder )
public androidx.loader.content.CursorLoader getAllSupportLoader( @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder )
{
return getAllSupportLoader( selection, selectionArgs, sortOrder, null );
}

public android.support.v4.content.CursorLoader getAllSupportLoader( @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder, @Nullable String join )
public androidx.loader.content.CursorLoader getAllSupportLoader( @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder, @Nullable String join )
{
return new android.support.v4.content.CursorLoader( getContext(), getContentUri(), getProjection( join ), selection, selectionArgs, sortOrder );
return new androidx.loader.content.CursorLoader( getContext(), getContentUri(), getProjection( join ), selection, selectionArgs, sortOrder );
}

public android.support.v4.content.CursorLoader getSupportLoaderFromId( long id )
public androidx.loader.content.CursorLoader getSupportLoaderFromId( long id )
{
return new android.support.v4.content.CursorLoader( getContext(), getRowContentUri( id ), tableColumns.getAll(), null, null, null );
return new androidx.loader.content.CursorLoader( getContext(), getRowContentUri( id ), tableColumns.getAll(), null, null, null );
}

public boolean isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.ensoft.restafari.database.converters.FloatFieldTypeConverter;
import com.ensoft.restafari.database.converters.IntegerFieldTypeConverter;
import com.ensoft.restafari.database.converters.LongFieldTypeConverter;
import com.ensoft.restafari.database.converters.JsonFieldTypeConverter;
import com.ensoft.restafari.database.converters.ShortFieldTypeConverter;
import com.ensoft.restafari.database.converters.StringFieldTypeConverter;
import com.ensoft.restafari.database.converters.UUIDFieldTypeConverter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.ensoft.restafari.database.annotations;


import android.support.annotation.IntDef;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import androidx.annotation.IntDef;

@Retention( RetentionPolicy.RUNTIME)
@Target( ElementType.FIELD)
public @interface DbForeignKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import java.util.Map;

public class MultipartEntity
{ public static final String TWO_HYPHENS = "--";
{
public static final String TWO_HYPHENS = "--";
public static final String LINE_END = "\r\n";

private final String boundary = "apiclient-" + System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.ensoft.restafari.network.helper;

import android.support.v4.util.Pair;

import com.google.gson.Gson;

import org.json.JSONArray;
Expand All @@ -12,6 +10,8 @@
import java.util.HashMap;
import java.util.Map;

import androidx.core.util.Pair;

public class RequestParameters extends JSONObject
{
public static RequestParameters fromObject( Object object )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.ensoft.restafari.network.rest.request;

import android.support.annotation.Nullable;

import org.json.JSONObject;

import androidx.annotation.Nullable;

public abstract class AsyncRequestContent
{
private AsyncRequestSentListener readyListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,47 @@
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonArrayRequest;
import com.ensoft.restafari.network.helper.NetworkLogHelper;
import com.ensoft.restafari.network.service.RequestService;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import androidx.annotation.Nullable;

public abstract class BaseJsonArrayRequest extends JsonArrayRequest
{
protected static final String TAG = BaseJsonArrayRequest.class.getSimpleName();

protected int method;
protected Map<String, String> headers;
@Nullable protected final String requestBody;

protected BaseJsonArrayRequest( int method, String url, JSONObject parameters, Map<String, String> headers, Listener<JSONArray> listener, ErrorListener errorListener )
{
super( method, url, parameters, listener, errorListener );
super( method, url, null, listener, errorListener );

this.method = method;
this.headers = headers;
this.requestBody = (parameters == null) ? null : parameters.toString();

if ( NetworkLogHelper.LOG_DEBUG_INFO )
Log.i(TAG, RequestLoggingHelper.getRequestText(this));
}

protected BaseJsonArrayRequest( int method, String url, JSONArray parameters, Map<String, String> headers, Listener<JSONArray> listener, ErrorListener errorListener )
{
super( method, url, parameters, listener, errorListener );
super( method, url, null, listener, errorListener );

this.method = method;
this.headers = headers;
this.requestBody = (parameters == null) ? null : parameters.toString();

if ( NetworkLogHelper.LOG_DEBUG_INFO )
Log.i(TAG, RequestLoggingHelper.getRequestText(this));
Expand Down Expand Up @@ -91,4 +98,16 @@ protected Response<JSONArray> parseNetworkResponse( NetworkResponse response) {

return super.parseNetworkResponse( response );
}

@Override
public byte[] getBody() {
try {
return requestBody == null ? null : requestBody.getBytes(PROTOCOL_CHARSET);
} catch ( UnsupportedEncodingException uee) {
VolleyLog.wtf(
"Unsupported Encoding while trying to get the bytes of %s using %s",
requestBody, PROTOCOL_CHARSET);
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,47 @@
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonObjectRequest;
import com.ensoft.restafari.network.helper.NetworkLogHelper;
import com.ensoft.restafari.network.service.RequestService;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import androidx.annotation.Nullable;

public abstract class BaseJsonRequest extends JsonObjectRequest
{
protected static final String TAG = BaseJsonRequest.class.getSimpleName();

protected int method;
protected Map<String, String> headers;
@Nullable protected final String requestBody;

protected BaseJsonRequest( int method, String url, JSONObject parameters, Map<String, String> headers, Listener<JSONObject> listener, ErrorListener errorListener )
{
super( method, url, parameters, listener, errorListener );
super( method, url, null, listener, errorListener );

this.method = method;
this.headers = headers;
this.requestBody = (parameters == null) ? null : parameters.toString();

if ( NetworkLogHelper.LOG_DEBUG_INFO )
Log.i(TAG, RequestLoggingHelper.getRequestText(this));
}

protected BaseJsonRequest( int method, String url, JSONArray parameters, Map<String, String> headers, Listener<JSONObject> listener, ErrorListener errorListener )
{
super( method, url, parameters.toString(), listener, errorListener );
super( method, url, null, listener, errorListener );

this.method = method;
this.headers = headers;
this.requestBody = (parameters == null) ? null : parameters.toString();

if ( NetworkLogHelper.LOG_DEBUG_INFO )
Log.i(TAG, RequestLoggingHelper.getRequestText(this));
Expand Down Expand Up @@ -83,12 +90,25 @@ protected void deliverResponse(JSONObject response)
}

@Override
protected Response<JSONObject> parseNetworkResponse( NetworkResponse response) {
protected Response<JSONObject> parseNetworkResponse( NetworkResponse response)
{
try
{
RequestService.getInstance().getResponseStatusManager().add( (long)getTag(), new com.ensoft.restafari.network.rest.response.NetworkResponse( response ) );
} catch ( Exception e ) { Log.i( TAG, e.toString() ); }

return super.parseNetworkResponse( response );
}

@Override
public byte[] getBody() {
try {
return requestBody == null ? null : requestBody.getBytes(PROTOCOL_CHARSET);
} catch ( UnsupportedEncodingException uee) {
VolleyLog.wtf(
"Unsupported Encoding while trying to get the bytes of %s using %s",
requestBody, PROTOCOL_CHARSET);
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.ensoft.restafari.network.rest.request;

import android.support.v4.util.Pair;
import android.util.Log;

import com.android.volley.AuthFailureError;
Expand All @@ -21,6 +20,8 @@
import java.util.List;
import java.util.Map;

import androidx.core.util.Pair;

public abstract class MultipartRequest<T> extends Request<T>
{
protected static final String TAG = BaseMultipartRequest.class.getSimpleName();
Expand Down
Loading

0 comments on commit 50242a9

Please sign in to comment.