Skip to content

Commit

Permalink
update code - loading UI finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza Amuzadeh committed Nov 14, 2018
1 parent c0882b5 commit 95227ff
Show file tree
Hide file tree
Showing 24 changed files with 338 additions and 139 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.negar.testone"
minSdkVersion 15
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand Down
72 changes: 72 additions & 0 deletions app/src/main/java/com/Vasl/Library/Android/LocaleHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.Vasl.Library.Android;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;

import java.util.Locale;

/**
* Created by Reza Amozadeh on 4/9/2017.
*/

public class LocaleHelper {

private static String LocalizationEN = "en";

private static String LocalizationFA = "fa";

public static void onAttach(Context context) {
LocaleHelper.setLocal(context);
}

public static void onAttach(Context context, String defaultLanguage) {
LocaleHelper.setLocal(context, defaultLanguage);
}

@SuppressWarnings("deprecation")
public static void setSystemLocaleLegacy(Configuration config, Locale locale) {
config.locale = locale;
}

@TargetApi(Build.VERSION_CODES.N)
public static void setSystemLocale(Configuration config, Locale locale) {
config.setLocale(locale);
}

public static void setLocal(Context context) {
setLocal(context, getLanguageSetting(context));
}

private static String getLanguageSetting(Context context) {
return LocalizationFA;
}

public static void setLocal(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);

Configuration config = new Configuration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
setSystemLocale(config, locale);
} else {
setSystemLocaleLegacy(config, locale);
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
context.getApplicationContext().getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
} else {
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
}
}

public static String getLocal() {
Locale localHelper = Locale.getDefault();
return localHelper.getLanguage();
}

public static Boolean isRTL() {
return getLocal().equals(LocalizationFA);
}

}
15 changes: 11 additions & 4 deletions app/src/main/java/com/Vasl/Library/Android/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.Vasl.Library.Android;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
Expand Down Expand Up @@ -45,6 +46,12 @@ public void run() {

}

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
LocaleHelper.onAttach(newBase);
}

private void myList() {

myCustomView.setStatus(ListStatuse.LOADING, null);
Expand Down Expand Up @@ -106,16 +113,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_load:
myCustomView.setStatus(ListStatuse.LOADING, null);
myCustomView.setStatus(ListStatuse.LOADING);
return true;
case R.id.action_success:
myCustomView.setStatus(ListStatuse.SUCCESS, null);
myCustomView.setStatus(ListStatuse.SUCCESS);
return true;
case R.id.action_failure:
myCustomView.setStatus(ListStatuse.FAILURE, "hellooo");
myCustomView.setStatus(ListStatuse.FAILURE);
return true;
case R.id.action_empty:
myCustomView.setStatus(ListStatuse.EMPTY, "no item");
myCustomView.setStatus(ListStatuse.EMPTY);
return true;
}
return false;
Expand Down
15 changes: 10 additions & 5 deletions recyclerlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 28

defaultConfig {
minSdkVersion 15
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand All @@ -19,21 +19,26 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

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

// SUPPORT LIBRARY
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'

implementation 'com.wang.avi:library:2.1.3'
testImplementation 'junit:junit:4.12'
// OTHERS
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.tuyenmonkey:mkloader:1.4.0'

// ANNOTATIONS
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

// TESTS
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.Vasl.recyclerlibrary.globalEnums.ListStatuse;
Expand All @@ -16,24 +17,24 @@
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

public class MyCustomView extends RelativeLayout implements View.OnClickListener
, SwipeRefreshLayout.OnRefreshListener {
public class MyCustomView extends RelativeLayout
implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener {

Context context;

// layout_loading
RelativeLayout loading;
LinearLayout loading;

// recycler view
RecyclerView recyclerView;

// empty view
RelativeLayout emptyHolder;
AppCompatTextView emptyTextView;
LinearLayout emptyHolder;
AppCompatTextView emptyTextViewTitle, emptyTextViewSubTitle;

// error view
RelativeLayout errorHolder;
AppCompatTextView errorTextView;
LinearLayout errorHolder;
AppCompatTextView errorTextViewTitle, errorTextViewSubTitle;
Button buttonRetry;

// swipe
Expand Down Expand Up @@ -73,18 +74,25 @@ public void init() {
buttonRetry = view.findViewById(R.id.button_retry);
buttonRetry.setOnClickListener(this);

// loading-view
loading = view.findViewById(R.id.loadingHolder);

// recycler-view
recyclerView = view.findViewById(R.id.recyclerView);

// swipe-view
swipeRefreshLayout = view.findViewById(R.id.swipeHolder);
swipeRefreshLayout.setOnRefreshListener(this);

// empty-view
emptyHolder = view.findViewById(R.id.emptyHolder);
emptyTextView = view.findViewById(R.id.emptyTextView);
emptyTextViewTitle = view.findViewById(R.id.emptyTextViewTitle);
emptyTextViewSubTitle = view.findViewById(R.id.emptyTextViewSubTitle);

//error-view
errorHolder = view.findViewById(R.id.errorHolder);
errorTextView = view.findViewById(R.id.errorTextView);
errorTextViewTitle = view.findViewById(R.id.errorTextViewTitle);
errorTextViewSubTitle = view.findViewById(R.id.errorTextViewSubTitle);

}

Expand All @@ -96,15 +104,27 @@ private void showLoading() {
loading.setVisibility(VISIBLE);
}

private void setErrorMsg(String msg){
if (!PublicFunction.StringIsEmptyOrNull(msg)) {
errorTextView.setText(msg);
private void setErrorTitle(@Nullable String title) {
if (!PublicFunction.StringIsEmptyOrNull(title)) {
errorTextViewTitle.setText(title);
}
}

private void setEmtpyMsg(String msg){
if (!PublicFunction.StringIsEmptyOrNull(msg)) {
emptyTextView.setText(msg);
private void setErrorSubTitle(@Nullable String subTitle) {
if (!PublicFunction.StringIsEmptyOrNull(subTitle)) {
errorTextViewSubTitle.setText(subTitle);
}
}

private void setEmptyTitle(@Nullable String title) {
if (!PublicFunction.StringIsEmptyOrNull(title)) {
emptyTextViewTitle.setText(title);
}
}

private void setEmptySubTitle(@Nullable String subtitle) {
if (!PublicFunction.StringIsEmptyOrNull(subtitle)) {
emptyTextViewSubTitle.setText(subtitle);
}
}

Expand Down Expand Up @@ -144,7 +164,7 @@ private void hideError() {
errorHolder.setVisibility(GONE);
}

public void setStatus(ListStatuse status,@Nullable String error) {
public void setStatus(ListStatuse status) {
switch (status) {
case LOADING:
showLoading();
Expand All @@ -165,15 +185,15 @@ public void setStatus(ListStatuse status,@Nullable String error) {
hideEmptyView();
hideRecyclerView();
hideSwipe();
setErrorMsg(error);
setErrorTitle(null);
showError();
break;
case EMPTY:
hideLoading();
hideRecyclerView();
hideSwipe();
hideError();
setEmtpyMsg(error);
setEmptyTitle(null);
showEmptyView();
break;
case UNDEFINE:
Expand All @@ -193,6 +213,54 @@ public void setStatus(ListStatuse status,@Nullable String error) {
}
}

public void setStatus(ListStatuse status, @Nullable String title) {
switch (status) {
case LOADING:
showLoading();
hideEmptyView();
hideRecyclerView();
hideSwipe();
hideError();
break;
case SUCCESS:
hideLoading();
hideEmptyView();
showRecyclerView();
hideSwipe();
hideError();
break;
case FAILURE:
hideLoading();
hideEmptyView();
hideRecyclerView();
hideSwipe();
setErrorTitle(title);
showError();
break;
case EMPTY:
hideLoading();
hideRecyclerView();
hideSwipe();
hideError();
setEmptyTitle(title);
showEmptyView();
break;
case UNDEFINE:
hideLoading();
hideEmptyView();
hideRecyclerView();
hideSwipe();
showError();
break;
default:
hideLoading();
hideEmptyView();
hideRecyclerView();
hideSwipe();
showError();
break;
}
}

@Override
public void onRefresh() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

import android.content.Context;
import android.content.res.TypedArray;
import androidx.appcompat.widget.AppCompatImageView;
import android.util.AttributeSet;

import com.Vasl.recyclerlibrary.R;

import androidx.appcompat.widget.AppCompatImageView;

public class CustomImageView extends AppCompatImageView {

boolean isCircle;
String gravity;
private boolean isCircle;

private String gravity;

private Context context;

public CustomImageView(Context context) {
Expand All @@ -19,6 +22,13 @@ public CustomImageView(Context context) {
init();
}

public CustomImageView(Context context, boolean isCircle) {
super(context);
this.context = context;
this.isCircle = isCircle;
init();
}

public CustomImageView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
Expand Down
Loading

0 comments on commit 95227ff

Please sign in to comment.