Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
eslam2010011 committed Jul 11, 2021
1 parent 4b77611 commit f334798
Show file tree
Hide file tree
Showing 286 changed files with 1,035 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment:2.3.4'
implementation 'androidx.navigation:navigation-ui:2.3.4'
implementation project(path: ':FastCountryCode')
implementation project(path: ':fast_country_code')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
2 changes: 2 additions & 0 deletions fast_country_code/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
1 change: 1 addition & 0 deletions fast_country_code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
2 changes: 2 additions & 0 deletions fast_country_code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# FastCountryCode

37 changes: 37 additions & 0 deletions fast_country_code/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
version='1'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Empty file.
21 changes: 21 additions & 0 deletions fast_country_code/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.fastcountrycode;

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("com.fastcountrycode.test", appContext.getPackageName());
}
}
5 changes: 5 additions & 0 deletions fast_country_code/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fastcountrycode">

</manifest>
100 changes: 100 additions & 0 deletions fast_country_code/src/main/java/com/fastcountrycode/Adapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.fastcountrycode;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;


import java.util.ArrayList;
import java.util.List;
import java.util.Locale;


public class Adapter extends RecyclerView.Adapter<Adapter.Holder> {

private List<Country> data;
CountryPickerListener countryPickerListener;

@SuppressWarnings("WeakerAccess")
protected class Holder extends RecyclerView.ViewHolder {
private View root;
TextView code;

Holder(View itemView) {
super(itemView);
root = itemView;

code = itemView.findViewById(R.id.code);


}
}

public Adapter(List<Country> data) {
this.data = data;

}

@SuppressWarnings("WeakerAccess")
public void setData(@Nullable List<Country> data) {
this.data.addAll(data);
notifyDataSetChanged();
}

@Override
public int getItemCount() {
return (isEmpty()) ? 0 : data.size();
}

@NonNull
@Override
public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.card_country_code, parent, false));
}

private boolean isEmpty() {
return data == null || data.isEmpty();
}

@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull Holder holder, int position) {

Country country = data.get(position);
holder.code.setText(country.getName());
holder.root.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (countryPickerListener != null) {
countryPickerListener.onSelectCountry(country);
}
}
});
}

public void search(String text) {
this.data.clear();
for (Country country : this.data) {
if (country.getName().toLowerCase(Locale.ENGLISH).contains(text.toLowerCase())) {
this.data.add(country);
}
}
this.notifyDataSetChanged();
}

public CountryPickerListener getCountryPickerListener() {
return countryPickerListener;
}

public void setCountryPickerListener(CountryPickerListener countryPickerListener) {
this.countryPickerListener = countryPickerListener;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.fastcountrycode;

import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.bottomsheet.BottomSheetDialog;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class BottomSheetCountryCode extends BottomSheetDialog {
RecyclerView list_country_code;
EditText search_country;
Adapter adapter;
List<Country> countriesList = new ArrayList<>();
List<Country> selectedCountriesList = new ArrayList<>();
ImageView close;

public BottomSheetCountryCode(@NonNull Context context) {
super(context, R.style.SheetDialog);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.country_code_layout);
setCountriesList(Country.getAllCountries());
init();
setAdapter();
}

public void init() {
list_country_code = findViewById(R.id.list_country_code);
search_country = findViewById(R.id.search_country);
close = findViewById(R.id.close);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});

}

public void setAdapter() {
this.selectedCountriesList = new ArrayList(this.countriesList.size());
this.selectedCountriesList.addAll(this.countriesList);
adapter = new Adapter(selectedCountriesList);
list_country_code.setLayoutManager(new LinearLayoutManager(getContext()));
list_country_code.setAdapter(adapter);
search_country.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable s) {
search(s.toString());
}
});

}

public Adapter getAdapter() {
return adapter;
}

private void search(String text) {
this.selectedCountriesList.clear();
for (Country country : this.countriesList) {
if (country.getName().toLowerCase(Locale.ENGLISH).contains(text.toLowerCase())) {
this.selectedCountriesList.add(country);
}
}

this.adapter.notifyDataSetChanged();
}

public void setCountriesList(List<Country> newCountries) {
this.countriesList.clear();
this.countriesList.addAll(newCountries);
}


}
Loading

0 comments on commit f334798

Please sign in to comment.