Skip to content

Commit

Permalink
Merge pull request #14 from santalu/development
Browse files Browse the repository at this point in the history
ConstraintLayout Implementation
  • Loading branch information
santalu authored Mar 14, 2018
2 parents 3e74b7f + 4e02a30 commit 68865ac
Show file tree
Hide file tree
Showing 31 changed files with 903 additions and 890 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ android:
- 'android-sdk-license-.+'
- 'google-gdk-license-.+'

before_install:
- yes | sdkmanager "platforms;android-27"

script:
- ./gradlew clean build
- ./gradlew clean build
49 changes: 26 additions & 23 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.santalu.myapplication"
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0."
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
compileSdkVersion 27
buildToolsVersion "27.0.3"

defaultConfig {
applicationId "com.santalu.myapplication"
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

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

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
testCompile 'junit:junit:4.12'
compile project(':library')
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:recyclerview-v7:27.1.0'
testImplementation 'junit:junit:4.12'
implementation project(':library')
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

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

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

/**
* Instrumentation test, which will execute on an Android device.
Expand All @@ -16,11 +15,11 @@
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.santalu.myapplication", appContext.getPackageName());
}
assertEquals("com.santalu.myapplication", appContext.getPackageName());
}
}
40 changes: 20 additions & 20 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.santalu.myapplication">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts"/>

</application>
</application>

</manifest>
154 changes: 154 additions & 0 deletions app/src/main/java/com/santalu/myapplication/EmptyHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package com.santalu.myapplication;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.TextUtils;
import android.view.View;
import com.santalu.emptyview.EmptyView;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.concurrent.TimeoutException;

/**
* Created by santalu on 31/08/2017.
* A simple helper class to demonstrate general usage of empty view
*/

public class EmptyHelper {

private final EmptyView emptyView;

public EmptyHelper(EmptyView emptyView) {
this.emptyView = emptyView;
}

public boolean isConnected(Context context) {
ConnectivityManager manager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getActiveNetworkInfo();
return info != null && info.isConnected();
}

public void showLoading() {
if (emptyView != null) {
emptyView.showLoading();
}
}

public void showLoading(CharSequence text) {
if (emptyView != null) {
emptyView.showLoading(text);
}
}

public void showLoading(int textId) {
if (emptyView != null) {
emptyView.showLoading(textId);
}
}

public void showContent() {
if (emptyView != null) {
emptyView.showContent();
}
}

public void showEmpty(View.OnClickListener listener) {
if (emptyView != null) {
if (isConnected(emptyView.getContext())) {
emptyView.setOnClickListener(listener);
emptyView.showEmpty();
} else {
showConnectionError(listener);
}
}
}

public void showEmpty(CharSequence text, View.OnClickListener listener) {
if (emptyView != null) {
emptyView.setOnClickListener(listener);
emptyView.showEmpty(text);
}
}

public void showEmpty(int textId, View.OnClickListener listener) {
if (emptyView != null) {
emptyView.setOnClickListener(listener);
emptyView.showEmpty(textId);
}
}

public void showError(View.OnClickListener listener) {
if (emptyView != null) {
emptyView.setOnClickListener(listener);
emptyView.showError();
}
}

public void showError(CharSequence text, View.OnClickListener listener) {
if (emptyView != null) {
emptyView.setOnClickListener(listener);
emptyView.showError(text);
}
}

public void showError(int textId, View.OnClickListener listener) {
if (emptyView != null) {
emptyView.setOnClickListener(listener);
emptyView.showError(textId);
}
}

public void showError(Throwable throwable, View.OnClickListener listener) {
if (emptyView != null) {
if (throwable == null || TextUtils.isEmpty(throwable.getMessage())) {
showError(R.string.emptyview_error_unknown, listener);
return;
}
Error error = Error.find(throwable);
switch (error) {
case ENDPOINT:
showEndpointError(listener);
break;
case TIMEOUT:
showTimeoutError(listener);
break;
case UNKNOWN:
showError(throwable.getMessage(), listener);
break;
}
}
}

public void showConnectionError(View.OnClickListener listener) {
showError(R.string.emptyview_error_connection_not_found, listener);
}

public void showTimeoutError(View.OnClickListener listener) {
showError(R.string.emptyview_error_connection_timeout, listener);
}

public void showEndpointError(View.OnClickListener listener) {
showError(R.string.emptyview_error_endpoint, listener);
}

enum Error {
ENDPOINT,
TIMEOUT,
UNKNOWN;

public static Error find(Throwable e) {
if (e instanceof UnknownHostException) {
return ENDPOINT;
} else if (e instanceof SocketTimeoutException
|| e instanceof TimeoutException
|| e instanceof ConnectException) {
return TIMEOUT;
} else {
return UNKNOWN;
}
}
}
}
Loading

0 comments on commit 68865ac

Please sign in to comment.