Browse Source

Language selection fixes on splash

master
preyearegmi 6 years ago
parent
commit
2ea369e97c
  1. 79
      app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/adapter/LanguageSelectionRVAdapter.java
  2. 38
      app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/model/LanguageModel.java
  3. 36
      app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/view/LanguageSelectionItemViewHolder.java
  4. 136
      app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/view/SplashScreen.java
  5. 8
      app/src/main/res/layout/activity_splash_screen_key_1.xml
  6. 7
      app/src/main/res/layout/activity_splash_screen_key_2.xml
  7. 2
      app/src/main/res/layout/fragment_splash_one.xml
  8. 2
      app/src/main/res/layout/fragment_splash_three.xml
  9. 2
      app/src/main/res/layout/fragment_splash_two.xml
  10. 42
      app/src/main/res/layout/splash_language_selection_item_view.xml

79
app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/adapter/LanguageSelectionRVAdapter.java

@ -0,0 +1,79 @@
package com.gmeremit.online.gmeremittance_native.splash_screen.adapter;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bumptech.glide.Glide;
import com.gmeremit.online.gmeremittance_native.R;
import com.gmeremit.online.gmeremittance_native.customwidgets.exchangecountrylistingdialog.CountryFlagMapper;
import com.gmeremit.online.gmeremittance_native.splash_screen.model.LanguageModel;
import com.gmeremit.online.gmeremittance_native.splash_screen.view.LanguageSelectionItemViewHolder;
import java.util.ArrayList;
import java.util.List;
public class LanguageSelectionRVAdapter extends RecyclerView.Adapter<LanguageSelectionItemViewHolder> {
private List<LanguageModel> languageModels;
private LanguageSelectionListener languageSelectionListener;
public LanguageSelectionRVAdapter()
{
languageModels=new ArrayList<>();
languageSelectionListener=null;
}
@NonNull
@Override
public LanguageSelectionItemViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.splash_language_selection_item_view,viewGroup,false);
return new LanguageSelectionItemViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull LanguageSelectionItemViewHolder holder, int i) {
LanguageModel data=languageModels.get(holder.getAdapterPosition());
int flagId= CountryFlagMapper.getFlagFromCountryCode(data.getCountryCode());
if(flagId!=-1)
{
Glide.with(holder.getImageView().getContext())
.load(flagId)
.into(holder.getImageView());
}
holder.setLanguageName(data.getCountryName());
holder.itemView.setOnClickListener(view->{
if(languageSelectionListener!=null)
languageSelectionListener.onLangugageSelected(data);
});
}
@Override
public int getItemCount() {
return languageModels.size();
}
public void setLanguageSelectionListener(LanguageSelectionListener listener)
{
this.languageSelectionListener=listener;
}
public void setData(List<LanguageModel> data)
{
if(data!=null&&data.size()>0)
{
this.languageModels=data;
notifyDataSetChanged();
}
}
public interface LanguageSelectionListener
{
void onLangugageSelected(LanguageModel languageModel);
}
}

38
app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/model/LanguageModel.java

@ -0,0 +1,38 @@
package com.gmeremit.online.gmeremittance_native.splash_screen.model;
public class LanguageModel {
String countryCode;
String localeCode;
String countryName;
public LanguageModel(String countryCode, String localeCode, String countryName) {
this.countryCode = countryCode;
this.localeCode = localeCode;
this.countryName = countryName;
}
public String getCountryCode() {
return countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public String getLocaleCode() {
return localeCode;
}
public void setLocaleCode(String localeCode) {
this.localeCode = localeCode;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
}

36
app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/view/LanguageSelectionItemViewHolder.java

@ -0,0 +1,36 @@
package com.gmeremit.online.gmeremittance_native.splash_screen.view;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.gmeremit.online.gmeremittance_native.R;
import butterknife.BindView;
import butterknife.ButterKnife;
public class LanguageSelectionItemViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.countryFlagImageView)
ImageView countryFlag;
@BindView(R.id.countryLanguageText)
TextView countryName;
public LanguageSelectionItemViewHolder(@NonNull View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
public ImageView getImageView()
{
return countryFlag;
}
public void setLanguageName(String name)
{
countryName.setText(name);
}
}

136
app/src/main/java/com/gmeremit/online/gmeremittance_native/splash_screen/view/SplashScreen.java

@ -2,6 +2,8 @@ package com.gmeremit.online.gmeremittance_native.splash_screen.view;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -16,10 +18,12 @@ import android.support.v4.content.ContextCompat;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPropertyAnimatorListenerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
@ -30,24 +34,30 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gmeremit.online.gmeremittance_native.GmeApplication;
import com.gmeremit.online.gmeremittance_native.R;
import com.gmeremit.online.gmeremittance_native.homeV2.view.HomeActivityV2;
import com.gmeremit.online.gmeremittance_native.loginV2.view.LoginV2Activity;
import com.gmeremit.online.gmeremittance_native.registerV2.view.RegisterV2Activity;
import com.gmeremit.online.gmeremittance_native.splash_screen.adapter.LanguageSelectionRVAdapter;
import com.gmeremit.online.gmeremittance_native.splash_screen.model.LanguageModel;
import com.gmeremit.online.gmeremittance_native.utils.KeyboardUtils;
import com.gmeremit.online.gmeremittance_native.utils.other.PersistenceStorageManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* Created by FMI-LT-17 on 2/9/2018.
*/
public class SplashScreen extends AppCompatActivity implements View.OnClickListener {
public class SplashScreen extends AppCompatActivity implements View.OnClickListener, LanguageSelectionRVAdapter.LanguageSelectionListener {
@BindView(R.id.view_pager)
ViewPager view_pager;
ViewPagerAdapter viewPagerAdapter;
@BindView(R.id.layoutDots)
@ -75,9 +85,11 @@ public class SplashScreen extends AppCompatActivity implements View.OnClickListe
private TextView[] dots;
LanguageViewTransitionManager languageViewTransitionManager;
/**
* ViewPager OnPageChangeListener Implementation
*/
LanguageSelectionRVAdapter languageSelectionRVAdapter;
LanguageModel selectedLanguage;
ViewPager.OnPageChangeListener viewPageChangeListener = new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
@ -108,7 +120,36 @@ public class SplashScreen extends AppCompatActivity implements View.OnClickListe
private void performDefaultAction(Bundle savedInstanceState) {
if (savedInstanceState == null) {
languageViewTransitionManager.underlineTitleText(true);
}
setDummyLanguageData();
}
}
private void setDummyLanguageData() {
List<LanguageModel> models = new ArrayList<>();
models.add(new LanguageModel("BD", "bd", "Bangladesh"));
models.add(new LanguageModel("KH", "th", "Cambodia"));
models.add(new LanguageModel("CN", "th", "China"));
models.add(new LanguageModel("KR", "th", "Korea"));
models.add(new LanguageModel("NP", "th", "Nepal"));
models.add(new LanguageModel("TH", "th", "Thailand"));
models.add(new LanguageModel("PK", "th", "Pakistan"));
models.add(new LanguageModel("PH", "th", "Philippines"));
models.add(new LanguageModel("LK", "th", "Sri Lanka"));
models.add(new LanguageModel("SG", "th", "Singapore"));
models.add(new LanguageModel("VN", "th", "Vietnam"));
models.add(new LanguageModel("RU", "th", "Russia"));
models.add(new LanguageModel("AZ", "th", "Azerbaijan"));
models.add(new LanguageModel("GE", "th", "Georgia"));
models.add(new LanguageModel("KJ", "th", "Kazakhstan"));
models.add(new LanguageModel("KD", "th", "Kyrgyzstan"));
models.add(new LanguageModel("MG", "th", "Moldova"));
models.add(new LanguageModel("TJ", "th", "Tajikistan"));
models.add(new LanguageModel("AE", "th", "UAE"));
models.add(new LanguageModel("UZ", "th", "Uzbekistan"));
models.add(new LanguageModel("BY", "th", "Belarus"));
models.add(new LanguageModel("MN", "th", "Mongolia"));
languageSelectionRVAdapter.setData(models);
}
private void init() {
@ -130,6 +171,10 @@ public class SplashScreen extends AppCompatActivity implements View.OnClickListe
view_pager.setAdapter(viewPagerAdapter);
view_pager.addOnPageChangeListener(viewPageChangeListener);
languageSelectionRVAdapter = new LanguageSelectionRVAdapter();
languageSelectionRVAdapter.setLanguageSelectionListener(this);
languageRv.setAdapter(languageSelectionRVAdapter);
KeyboardUtils.forceCloseKeyboard(view_pager.getRootView());
}
@ -211,12 +256,56 @@ public class SplashScreen extends AppCompatActivity implements View.OnClickListe
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
@Override
public void onLangugageSelected(LanguageModel languageModel) {
if (this.selectedLanguage == null) {
this.selectedLanguage = languageModel;
changeLocale(this.selectedLanguage.getLocaleCode());
} else {
if (!this.selectedLanguage.getCountryCode().equalsIgnoreCase(languageModel.getCountryCode())) {
this.selectedLanguage = languageModel;
changeLocale(this.selectedLanguage.getLocaleCode());
}
}
}
private void changeLocale(String localeCode) {
Locale locale = new Locale(localeCode);
Locale.setDefault(locale);
// Create a new configuration object
Configuration config = new Configuration();
// Set the locale of the new configuration
config.locale = locale;
// Update the configuration of the Accplication context
Resources res= getResources();
res.updateConfiguration(
config,
getResources().getDisplayMetrics()
);
GmeApplication.getStringExtractor().updateResources(res);
try {
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
// restart(this,500);
}
catch(NullPointerException ne)
{
}
// performLogout();
}
public class ViewPagerAdapter extends PagerAdapter {
private LayoutInflater layoutInflater;
@ -272,6 +361,7 @@ public class SplashScreen extends AppCompatActivity implements View.OnClickListe
overshootInterpolator = new OvershootInterpolator();
accelerateDecelerateInterpolator = new AccelerateDecelerateInterpolator();
textViewPaintFlags = selectedLanguageText.getPaintFlags();
}
public void showLanguageView(Runnable onAnimationCompleteCallback) {
@ -287,6 +377,14 @@ public class SplashScreen extends AppCompatActivity implements View.OnClickListe
userNavigatedToLanguageView = false;
isAnimationOnProgress = true;
ViewCompat.animate(view_pager).withLayer().alpha(0f).setDuration(FADE_IN_OUT_DURATION).setInterpolator(accelerateDecelerateInterpolator)
.setListener(new ViewPropertyAnimatorListenerAdapter() {
@Override
public void onAnimationEnd(View view) {
super.onAnimationEnd(view);
if (view_pager.getVisibility() == View.VISIBLE)
view_pager.setVisibility(View.GONE);
}
})
.withStartAction(() -> ViewCompat.animate(languageRv).withLayer().alpha(1f).setDuration(FADE_IN_OUT_DURATION).setInterpolator(accelerateDecelerateInterpolator).start());
}
@ -305,7 +403,7 @@ public class SplashScreen extends AppCompatActivity implements View.OnClickListe
constraintSet.applyTo(rootLayout);
}
public void underlineTitleText(boolean action) {
void underlineTitleText(boolean action) {
if (action)
selectedLanguageText.setPaintFlags(textViewPaintFlags | Paint.UNDERLINE_TEXT_FLAG);
else
@ -313,7 +411,7 @@ public class SplashScreen extends AppCompatActivity implements View.OnClickListe
selectedLanguageText.invalidate();
}
public void hideLanguage(Runnable onAnimationCompleteCallback) {
void hideLanguage(Runnable onAnimationCompleteCallback) {
constraintSet.clone(context, R.layout.activity_splash_screen_key_1);
@ -324,14 +422,23 @@ public class SplashScreen extends AppCompatActivity implements View.OnClickListe
@Override
public void onTransitionStart(@NonNull Transition transition) {
super.onTransitionStart(transition);
underlineTitleText(true);
userNavigatedToLanguageView = true;
isAnimationOnProgress = true;
iv_back.setVisibility(View.INVISIBLE);
ViewCompat.animate(view_pager).withLayer().alpha(1f).setDuration(FADE_IN_OUT_DURATION).setInterpolator(accelerateDecelerateInterpolator)
.setListener(new ViewPropertyAnimatorListenerAdapter(){
@Override
public void onAnimationStart(View view) {
super.onAnimationStart(view);
if(view_pager.getVisibility()!=View.VISIBLE)
{
view_pager.setVisibility(View.INVISIBLE);
view_pager.setAlpha(0f);
view_pager.setVisibility(View.VISIBLE);
}
}
})
.withStartAction(() -> ViewCompat.animate(languageRv).withLayer().alpha(0f).setDuration(FADE_IN_OUT_DURATION).setInterpolator(accelerateDecelerateInterpolator).start());
}
@ -357,6 +464,9 @@ public class SplashScreen extends AppCompatActivity implements View.OnClickListe
public boolean isUserOnLanguageSelectionView() {
return this.userNavigatedToLanguageView;
}
}
}

8
app/src/main/res/layout/activity_splash_screen_key_1.xml

@ -62,23 +62,25 @@
/>
<android.support.v7.widget.RecyclerView
android:paddingTop="15dp"
android:scrollbars="vertical"
android:id="@+id/languageRv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#33000000"
android:layout_marginTop="18dp"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/view_pager"
app:layout_constraintTop_toBottomOf="@+id/selectedLanguageText"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
/>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="153dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

7
app/src/main/res/layout/activity_splash_screen_key_2.xml

@ -33,9 +33,11 @@
app:layout_constraintStart_toStartOf="parent" />
<android.support.v7.widget.RecyclerView
android:paddingTop="15dp"
android:id="@+id/languageRv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scrollbars="vertical"
android:layout_marginTop="18dp"
android:background="#33000000"
android:visibility="visible"
@ -76,11 +78,10 @@
android:id="@+id/view_pager"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/layoutDots"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/languageRv" />
app:layout_constraintTop_toBottomOf="@+id/selectedLanguageIcon" />
<LinearLayout
android:id="@+id/layoutDots"

2
app/src/main/res/layout/fragment_splash_one.xml

@ -20,7 +20,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.32" />
app:layout_constraintVertical_bias="0.13" />
<com.gmeremit.online.gmeremittance_native.customwidgets.GmeTextView
android:id="@+id/gmeTextView2"

2
app/src/main/res/layout/fragment_splash_three.xml

@ -18,7 +18,7 @@ android:background="@color/colorPrimary">
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.32" />
app:layout_constraintVertical_bias="0.13" />
<com.gmeremit.online.gmeremittance_native.customwidgets.GmeTextView
android:id="@+id/gmeTextView2"

2
app/src/main/res/layout/fragment_splash_two.xml

@ -18,7 +18,7 @@ android:background="@color/colorPrimary">
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.32" />
app:layout_constraintVertical_bias="0.13" />
<com.gmeremit.online.gmeremittance_native.customwidgets.GmeTextView
android:id="@+id/gmeTextView2"

42
app/src/main/res/layout/splash_language_selection_item_view.xml

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@android:color/transparent"
android:layout_marginBottom="2dp"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/countryFlagImageView"
android:layout_width="55dp"
android:layout_height="45dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:src="@drawable/flag_korean"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.gmeremit.online.gmeremittance_native.customwidgets.GmeTextView
android:id="@+id/countryLanguageText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/select_language_text"
android:textColor="@color/white"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="@+id/countryFlagImageView"
app:layout_constraintStart_toEndOf="@+id/countryFlagImageView"
app:layout_constraintTop_toTopOf="@+id/countryFlagImageView"
app:layout_constraintVertical_bias="0.49"
app:txtfontName="@string/regular" />
</android.support.constraint.ConstraintLayout>
Loading…
Cancel
Save