-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from santalu/development
ConstraintLayout Implementation
- Loading branch information
Showing
31 changed files
with
903 additions
and
890 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
app/src/main/java/com/santalu/myapplication/EmptyHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.