Skip to content

Commit

Permalink
Add language option in create and restore view (Scroll Language in In…
Browse files Browse the repository at this point in the history
…tro Activity) (#167)

* Added audios and audios data source

* Changed Intro's UI, Added Adapter, and Added country resources.

* Convert CountryLanguageAdapter to Kotlin, added shadow and made text item bold when selected

* Added audio feature to play the language on each item

* Added pop up yes or no UI

* Added pop up yes or cancel

* Change text's sizes
  • Loading branch information
josikie authored Mar 20, 2024
1 parent cc1972d commit 4da5617
Show file tree
Hide file tree
Showing 42 changed files with 739 additions and 137 deletions.
1 change: 0 additions & 1 deletion .idea/inspectionProfiles/Project_Default.xml

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

10 changes: 10 additions & 0 deletions app/src/main/java/com/breadwallet/entities/CountryAudio.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.breadwallet.entities

@Retention(AnnotationRetention.RUNTIME)
annotation class AudioRes

data class CountryAudio(
val langDescription : String,
val langQuestion : String,
@AudioRes val langAudio : Int
)
10 changes: 10 additions & 0 deletions app/src/main/java/com/breadwallet/entities/IntroLanguage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.breadwallet.entities

import android.net.Uri

data class IntroLanguage(
val lang : String,
val desc : String,
val audio : Int,
val message: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.breadwallet.entities

import com.breadwallet.R

class IntroLanguageResource {

fun loadResources() : Array<IntroLanguage>{
return arrayOf<IntroLanguage> (
IntroLanguage(Language.ENGLISH.title, "The most secure and safest way to use Litecoin.", R.raw.english, "Are you sure you want to change the language to English?"),
IntroLanguage(Language.SPANISH.title, "La forma más segura de usar Litecoin.", R.raw.spanish, "¿Estás seguro de que quieres cambiar el idioma a español?"),
IntroLanguage(Language.INDONESIAN.title, "Cara paling aman dan teraman untuk menggunakan Litecoin.", R.raw.bahasaindonesia, "Yakin ingin mengubah bahasanya ke bahasa Indonesia?"),
IntroLanguage(Language.GERMAN.title, "Die sicherste Option zur Nutzung von Litecoin.", R.raw.deutsch, "Sind Sie sicher, dass Sie die Sprache auf Deutsch ändern möchten?"),
IntroLanguage(Language.UKRAINIAN.title, "Найбезпечніший і найбезпечніший спосіб використання Litecoin.", R.raw.ukrainian, "Ви впевнені, що хочете змінити мову на українську?"),
IntroLanguage(Language.CHINESE_TRADITIONAL.title, "使用萊特幣最安全、最有保障的方式。", R.raw.traditionalchinese, "您確定要將語言改為中文嗎?"),
IntroLanguage(Language.ITALIAN.title, "Il modo più sicuro per usare i Litecoin.", R.raw.italiano, "Sei sicuro di voler cambiare la lingua in italiano?"),
IntroLanguage(Language.KOREAN.title, "Litecoin을 사용하는 가장 안정되고 안전한 방법.", R.raw.korean, "언어를 한국어로 변경하시겠습니까?"),
IntroLanguage(Language.FRENCH.title, "La façon la plus sécurisée et sûre d'utiliser Litecoin.", R.raw.french, "Êtes-vous sûr de vouloir changer la langue en français ?"),
IntroLanguage(Language.TURKISH.title, "Litecoin'i kullanmanın en güvenli ve en güvenli yolu.", R.raw.turkish, "Dili türkçeye değiştirmek istediğinizden emin misiniz?"),
IntroLanguage(Language.JAPANESE.title, "最も安全にリテコインを使う手段。", R.raw.japanese, "言語を日本語に変更してもよろしいですか?"),
IntroLanguage(Language.PORTUGUESE.title, "A forma mais protegida e segura de utilizar a Litecoin.", R.raw.portugues, "Tem certeza de que deseja alterar o idioma para português?"),
IntroLanguage(Language.RUSSIAN.title, "Самый надежный и безопасный способ использования биткойна.", R.raw.russian, "Вы уверены, что хотите сменить язык на русский?")
)
}
}
11 changes: 9 additions & 2 deletions app/src/main/java/com/breadwallet/entities/Language.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.breadwallet.entities

import com.breadwallet.R
import java.util.Locale


/** Litewallet
* Created by Mohamed Barry on 7/19/21
* email: [email protected]
* Copyright © 2021 Litecoin Foundation. All rights reserved.
*/
enum class Language(val code: String, val title: String, val desc: String) {
GERMAN("de", "Deutsch", "Sprache auswählen"),
enum class Language(
val code: String,
val title: String,
val desc: String
) {
ENGLISH("en", "English", "Select language"),
GERMAN("de", "Deutsch", "Sprache auswählen"),
SPANISH("es", "Español", "Seleccione el idioma"),
FRENCH("fr", "Français", "Sélectionner la langue"),
INDONESIAN("in", "Indonesia", "Pilih bahasa"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@

package com.breadwallet.presenter.activities.intro;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Point;
import android.media.AudioAttributes;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.breadwallet.entities.IntroLanguageResource;
import com.breadwallet.tools.adapter.CountryLanguageAdapter;
import com.breadwallet.tools.listeners.RecyclerItemClickListener;
import com.google.android.material.snackbar.Snackbar;

import com.breadwallet.BuildConfig;
import com.breadwallet.R;
import com.breadwallet.presenter.activities.BreadActivity;
Expand All @@ -25,7 +38,12 @@
import com.breadwallet.wallet.BRWalletManager;
import com.platform.APIClient;

import org.w3c.dom.Text;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.Objects;

import timber.log.Timber;

Expand All @@ -35,14 +53,13 @@ public class IntroActivity extends BRActivity implements Serializable {
public static IntroActivity introActivity;
public static boolean appVisible = false;
private static IntroActivity app;
private TextView versionText;

public RecyclerView listLangRecyclerView;
public IntroLanguageResource introLanguageResource = new IntroLanguageResource();
public static IntroActivity getApp() {
return app;
}

public static final Point screenParametersPoint = new Point();

@Override
protected void onRestart() {
super.onRestart(); // Always call the superclass method first
Expand All @@ -52,10 +69,38 @@ protected void onRestart() {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
Log.i("Some", getPackageName());
newWalletButton = (Button) findViewById(R.id.button_new_wallet);
recoverWalletButton = (Button) findViewById(R.id.button_recover_wallet);
versionText = findViewById(R.id.version_text);
TextView description = findViewById(R.id.textView);

TextView versionText = findViewById(R.id.version_text);
listLangRecyclerView = findViewById(R.id.language_list);
View parentLayout = findViewById(android.R.id.content);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
CountryLanguageAdapter countryLanguageAdapter = new CountryLanguageAdapter(this, introLanguageResource.loadResources());
listLangRecyclerView.setAdapter(countryLanguageAdapter);

listLangRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();

int centerPosition = (lastVisibleItemPosition - firstVisibleItemPosition) / 2 + firstVisibleItemPosition;
if (centerPosition != RecyclerView.NO_POSITION) {
countryLanguageAdapter.updateCenterPosition(centerPosition);
description.setText(countryLanguageAdapter.selectedDesc());
showDialogForItem(countryLanguageAdapter.selectedMessage());
}
}
}

});

listLangRecyclerView.setLayoutManager(layoutManager);

setListeners();
updateBundles();
Expand Down Expand Up @@ -100,6 +145,30 @@ public void onClick(View view) {
PostAuth.getInstance().onCanaryCheck(this, false);
}

private void showDialogForItem(String title) {
Dialog dialog = new Dialog(IntroActivity.this);
dialog.setContentView(R.layout.pop_up_language_intro);
Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(R.drawable.rounded_pop_up_intro);
Button btnYes = dialog.findViewById(R.id.button_yes);
Button btnNo = dialog.findViewById(R.id.button_no);
TextView txtTitle = dialog.findViewById(R.id.dialog_message);
txtTitle.setText(title);
btnYes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});

btnNo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}

private void updateBundles() {
BRExecutor.getInstance().forBackgroundTasks().execute(new Runnable() {
@Override
Expand Down
Loading

0 comments on commit 4da5617

Please sign in to comment.