From a1b736682dbaae96591a0e4a5a311b65b384e283 Mon Sep 17 00:00:00 2001 From: Gonzalo Galeano Date: Sat, 29 May 2021 01:57:43 -0400 Subject: [PATCH 1/8] =?UTF-8?q?separando=20el=20valor=20(host=5Fname)=20no?= =?UTF-8?q?mbre=20del=20servidor=20en=20archivos=20seg=C3=BAn=20su=20entor?= =?UTF-8?q?no=20(debug,=20release)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/debug/res/values/strings.xml | 4 ++++ app/src/release/res/values/strings.xml | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 app/src/debug/res/values/strings.xml create mode 100644 app/src/release/res/values/strings.xml diff --git a/app/src/debug/res/values/strings.xml b/app/src/debug/res/values/strings.xml new file mode 100644 index 0000000..30ae030 --- /dev/null +++ b/app/src/debug/res/values/strings.xml @@ -0,0 +1,4 @@ + + + http://192.168.0.33:8080 + \ No newline at end of file diff --git a/app/src/release/res/values/strings.xml b/app/src/release/res/values/strings.xml new file mode 100644 index 0000000..30ae030 --- /dev/null +++ b/app/src/release/res/values/strings.xml @@ -0,0 +1,4 @@ + + + http://192.168.0.33:8080 + \ No newline at end of file From eeb5090ce9de79a3af52acb11c0dc6dd3ea3b4cb Mon Sep 17 00:00:00 2001 From: Gonzalo Galeano Date: Sat, 29 May 2021 01:59:49 -0400 Subject: [PATCH 2/8] =?UTF-8?q?peque=C3=B1a=20correcci=C3=B3n=20y=20para?= =?UTF-8?q?=20configurar=20para=20entorno=20desarrollo=20debe=20ser=20agre?= =?UTF-8?q?gado=20el=20host=20en=20este=20archivo=20y=20en=20el=20valor=20?= =?UTF-8?q?host=5Fname=20en:=20app/src/debug/res/values/strings.xml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/xml/network_security_config.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/xml/network_security_config.xml b/app/src/main/res/xml/network_security_config.xml index ba61c77..65d70a3 100644 --- a/app/src/main/res/xml/network_security_config.xml +++ b/app/src/main/res/xml/network_security_config.xml @@ -1,9 +1,8 @@ + sodep.com.py - - 192.168.0.33 - + 192.168.0.33 \ No newline at end of file From 05cfda69891baf26fa5c6be0593364a6b8d72f34 Mon Sep 17 00:00:00 2001 From: Gonzalo Galeano Date: Sat, 29 May 2021 02:01:01 -0400 Subject: [PATCH 3/8] quitando el nombre del servidor en los valores de las url --- app/src/main/res/values/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bd24885..5a9c3d8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -46,8 +46,8 @@ New password must have at least 8 characters Ud. no aceptó aún los términos de uso de la aplicación. Por favor lea hasta el final y marque la casilla de aceptación si está de acuerdo con las condiciones http://example.com/ - http://192.168.0.33:8080/api/login - http://192.168.0.33:8080/api/token/user-access + /api/login + /api/token/user-access https://restcountries.eu/rest/v2/all?fields=name;alpha2Code Aviso Legal de Responsabilidades From 433295e1adda0e32141f8d368483474f89d799ae Mon Sep 17 00:00:00 2001 From: Gonzalo Galeano Date: Sat, 29 May 2021 02:01:17 -0400 Subject: [PATCH 4/8] =?UTF-8?q?separando=20host=5Fname=20y=20end=5Fpoint?= =?UTF-8?q?=20en=20los=20c=C3=B3digos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/github/jokoframework/activity/LoginActivity.java | 4 +++- .../jokoframework/activity/SecondAuthenticationActivity.java | 5 ++++- .../java/io/github/jokoframework/otp/edit/SaveActivity.java | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/github/jokoframework/activity/LoginActivity.java b/app/src/main/java/io/github/jokoframework/activity/LoginActivity.java index 5e2c8fd..5b16fa3 100644 --- a/app/src/main/java/io/github/jokoframework/activity/LoginActivity.java +++ b/app/src/main/java/io/github/jokoframework/activity/LoginActivity.java @@ -299,7 +299,9 @@ private void loginJWT(LoginRequest loginRequest) { // Instanciar el RequestQueue. RequestQueue queue = Volley.newRequestQueue(this); - String url = getString(R.string.jwt_URL); + String host_name = getString(R.string.host_name); + String end_point = getString(R.string.jwt_URL); + String url = host_name + end_point; Map params = new HashMap(); params.put("username", loginRequest.getUsername()); diff --git a/app/src/main/java/io/github/jokoframework/activity/SecondAuthenticationActivity.java b/app/src/main/java/io/github/jokoframework/activity/SecondAuthenticationActivity.java index 0a06b09..dbf84b2 100644 --- a/app/src/main/java/io/github/jokoframework/activity/SecondAuthenticationActivity.java +++ b/app/src/main/java/io/github/jokoframework/activity/SecondAuthenticationActivity.java @@ -58,7 +58,10 @@ private void initializeUI(){ private void otpValid(View view){ RequestQueue queue = Volley.newRequestQueue(this); - String url = getString(R.string.user_acces_URL); + + String host_name = getString(R.string.host_name); + String end_point = getString(R.string.user_acces_URL); + String url = host_name + end_point; final Context ctx = view.getContext(); Intent intent = new Intent(ctx, HomeActivity.class); diff --git a/app/src/main/java/io/github/jokoframework/otp/edit/SaveActivity.java b/app/src/main/java/io/github/jokoframework/otp/edit/SaveActivity.java index 83304f6..c59d04a 100644 --- a/app/src/main/java/io/github/jokoframework/otp/edit/SaveActivity.java +++ b/app/src/main/java/io/github/jokoframework/otp/edit/SaveActivity.java @@ -54,7 +54,10 @@ public void onClick(View v) { private void saveSeed(Token token){ RequestQueue queue = Volley.newRequestQueue(this); - String url = getString(R.string.user_acces_URL); //<--saveseed_URL url to request, change values/strings.xml + // saveseed_URL url to request, change values/strings.xml + String host_name = getString(R.string.host_name); + String end_point = getString(R.string.user_acces_URL); + String url = host_name + end_point; //Creates parameters Map params = new HashMap(); From 2320036f7f111f1e9fffcf5652fb67b943e4ae04 Mon Sep 17 00:00:00 2001 From: Gonzalo Galeano Date: Sat, 29 May 2021 02:17:59 -0400 Subject: [PATCH 5/8] Documentando cambios MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mencionando los cambios necesarios para apuntar a distintos nombres de servidores según se necesite en desarrollo o producción --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index fa25554..397295d 100644 --- a/README.md +++ b/README.md @@ -103,3 +103,11 @@ Para cambiar a cualquier login JWT, se deben cambiar algunos parametros en login - url: Esta debe apuntar al servidor que se desea consultar. Ubicado en app/src/main/res/values/strings.xml como jwt_URL. - jsonRequest: Debe contener los datos necesarios para el servidor. En este caso se utilizaron solo 2 campos, username y password. - listener y errorListener: Aca se definen las acciones a tomar ya sea esperando una respuesta positiva, negativa o un error. + +## Configurar Entorno de Desarrollo + +Configurar el nombre de servidor en los siguientes archivos: + +app/src/main/res/xml/network_security_config.xml () + +app/src/debug/res/values/strings.xml (host_name) From 8f31d9f1d0f8d0dbe8a632a87b12f6f911a6b4d6 Mon Sep 17 00:00:00 2001 From: Gonzalo Galeano Date: Sat, 29 May 2021 02:19:28 -0400 Subject: [PATCH 6/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 397295d..6eb0fc0 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,6 @@ Para cambiar a cualquier login JWT, se deben cambiar algunos parametros en login Configurar el nombre de servidor en los siguientes archivos: -app/src/main/res/xml/network_security_config.xml () +app/src/main/res/xml/network_security_config.xml ( etiqueta: domain ) app/src/debug/res/values/strings.xml (host_name) From 9b3546505feb5fca0712de112f55631836e10d78 Mon Sep 17 00:00:00 2001 From: Gonzalo Galeano Date: Wed, 2 Jun 2021 08:29:02 -0400 Subject: [PATCH 7/8] obteniendo valor para hostname mediante prompt --- app/src/debug/res/values/strings.xml | 4 -- .../debug/res/xml/network_security_config.xml | 4 ++ .../jokoframework/activity/LoginActivity.java | 6 +-- .../SecondAuthenticationActivity.java | 7 +-- .../jokoframework/otp/edit/SaveActivity.java | 7 ++- .../jokoframework/singleton/MboehaoApp.java | 49 ++++++++++++++++++- .../main/res/layout/prompt_hostname_view.xml | 20 ++++++++ app/src/release/res/values/strings.xml | 4 -- .../res/xml/network_secure_config.xml} | 1 - 9 files changed, 82 insertions(+), 20 deletions(-) delete mode 100644 app/src/debug/res/values/strings.xml create mode 100644 app/src/debug/res/xml/network_security_config.xml create mode 100644 app/src/main/res/layout/prompt_hostname_view.xml delete mode 100644 app/src/release/res/values/strings.xml rename app/src/{main/res/xml/network_security_config.xml => release/res/xml/network_secure_config.xml} (81%) diff --git a/app/src/debug/res/values/strings.xml b/app/src/debug/res/values/strings.xml deleted file mode 100644 index 30ae030..0000000 --- a/app/src/debug/res/values/strings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - http://192.168.0.33:8080 - \ No newline at end of file diff --git a/app/src/debug/res/xml/network_security_config.xml b/app/src/debug/res/xml/network_security_config.xml new file mode 100644 index 0000000..dca93c0 --- /dev/null +++ b/app/src/debug/res/xml/network_security_config.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/io/github/jokoframework/activity/LoginActivity.java b/app/src/main/java/io/github/jokoframework/activity/LoginActivity.java index 5b16fa3..55d4528 100644 --- a/app/src/main/java/io/github/jokoframework/activity/LoginActivity.java +++ b/app/src/main/java/io/github/jokoframework/activity/LoginActivity.java @@ -42,6 +42,7 @@ import io.github.jokoframework.model.UserAccessResponse; import io.github.jokoframework.model.UserData; import io.github.jokoframework.otp.OtpActivityNotLogged; +import io.github.jokoframework.singleton.MboehaoApp; import io.github.jokoframework.utilities.AppUtils; import rx.Observable; import rx.Subscriber; @@ -95,6 +96,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); initializeUI(); + MboehaoApp.prompDevHostName(this); } private void initializeUI() { @@ -299,9 +301,7 @@ private void loginJWT(LoginRequest loginRequest) { // Instanciar el RequestQueue. RequestQueue queue = Volley.newRequestQueue(this); - String host_name = getString(R.string.host_name); - String end_point = getString(R.string.jwt_URL); - String url = host_name + end_point; + String url = MboehaoApp.getHostName() + getString(R.string.jwt_URL); Map params = new HashMap(); params.put("username", loginRequest.getUsername()); diff --git a/app/src/main/java/io/github/jokoframework/activity/SecondAuthenticationActivity.java b/app/src/main/java/io/github/jokoframework/activity/SecondAuthenticationActivity.java index dbf84b2..9a8b2cf 100644 --- a/app/src/main/java/io/github/jokoframework/activity/SecondAuthenticationActivity.java +++ b/app/src/main/java/io/github/jokoframework/activity/SecondAuthenticationActivity.java @@ -18,11 +18,13 @@ import io.github.jokoframework.R; import io.github.jokoframework.mboehaolib.util.Utils; +import io.github.jokoframework.singleton.MboehaoApp; public class SecondAuthenticationActivity extends BaseActivity { private EditText otpTextField; private String secret; private Activity thisActivity; + public Activity thisActivity() { return thisActivity; } @@ -34,6 +36,7 @@ protected void onCreate(Bundle savedInstanceState) { Bundle b = getIntent().getExtras(); assert b != null; secret = (String) b.get("SECRET"); + MboehaoApp.prompDevHostName(this); } private void initializeUI(){ @@ -59,9 +62,7 @@ private void initializeUI(){ private void otpValid(View view){ RequestQueue queue = Volley.newRequestQueue(this); - String host_name = getString(R.string.host_name); - String end_point = getString(R.string.user_acces_URL); - String url = host_name + end_point; + String url = MboehaoApp.getHostName() + getString(R.string.user_acces_URL); final Context ctx = view.getContext(); Intent intent = new Intent(ctx, HomeActivity.class); diff --git a/app/src/main/java/io/github/jokoframework/otp/edit/SaveActivity.java b/app/src/main/java/io/github/jokoframework/otp/edit/SaveActivity.java index c59d04a..9014e1c 100644 --- a/app/src/main/java/io/github/jokoframework/otp/edit/SaveActivity.java +++ b/app/src/main/java/io/github/jokoframework/otp/edit/SaveActivity.java @@ -21,10 +21,10 @@ import io.github.jokoframework.mboehaolib.util.Utils; import io.github.jokoframework.otp.token.Token; import io.github.jokoframework.otp.token.TokenPersistence; +import io.github.jokoframework.singleton.MboehaoApp; public class SaveActivity extends BaseActivity { - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -49,15 +49,14 @@ public void onClick(View v) { finish(); } }); + MboehaoApp.prompDevHostName(this); } private void saveSeed(Token token){ RequestQueue queue = Volley.newRequestQueue(this); // saveseed_URL url to request, change values/strings.xml - String host_name = getString(R.string.host_name); - String end_point = getString(R.string.user_acces_URL); - String url = host_name + end_point; + String url = MboehaoApp.getHostName() + getString(R.string.user_acces_URL); //Creates parameters Map params = new HashMap(); diff --git a/app/src/main/java/io/github/jokoframework/singleton/MboehaoApp.java b/app/src/main/java/io/github/jokoframework/singleton/MboehaoApp.java index 4277e52..712373f 100644 --- a/app/src/main/java/io/github/jokoframework/singleton/MboehaoApp.java +++ b/app/src/main/java/io/github/jokoframework/singleton/MboehaoApp.java @@ -1,12 +1,17 @@ package io.github.jokoframework.singleton; +import android.app.Activity; +import android.app.AlertDialog; import android.app.Application; import android.content.Context; import android.content.Intent; import android.preference.PreferenceManager; import androidx.multidex.MultiDex; import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; import android.widget.Toast; import com.crashlytics.android.Crashlytics; @@ -35,6 +40,9 @@ public class MboehaoApp extends Application { private static Context singletonApplicationContext; private static MboehaoApp mySelf; + private static String hostName = "https://sodep.com.py"; + private static Boolean devHostNameDefined = false; + /** * Instance variables */ @@ -80,6 +88,45 @@ public void onCreate() { MboehaoApp.setSingletonApplicationContext(this.getApplicationContext()); } + public static void setHostName(String newHostName){ + hostName = newHostName; + } + + public static String getHostName(){ + return hostName; + } + + public static void prompDevHostName(Activity ctx) { + if ( BuildConfig.DEBUG ) { + if ( !devHostNameDefined ) { + AlertDialog.Builder builder = new AlertDialog.Builder(ctx); + LayoutInflater inflater = ctx.getLayoutInflater(); + + View view = inflater.inflate(R.layout.prompt_hostname_view, null); + EditText inputHostName = view.findViewById(R.id.hostNameInput); + + builder.setView(view) + .setPositiveButton(R.string.button_accept, (dialog, id) -> { + if ( inputHostName.getText().toString().equals("") ) { + MboehaoApp.prompDevHostName(ctx); + return; + } + MboehaoApp.setHostName(inputHostName.getText().toString()); + devHostNameDefined = true; + }) + .setNegativeButton(R.string.button_cancel, (dialog, id) -> { + if ( inputHostName.getText().toString().equals("") ) { + MboehaoApp.prompDevHostName(ctx); + } + dialog.cancel(); + }); + + AlertDialog dialog = builder.create(); + dialog.show(); + } + } + } + public OkHttpClient.Builder getHttpClient() { return httpClient; } @@ -122,7 +169,7 @@ public static void setSingletonApplicationContext(Context singletonApplicationCo synchronized public Tracker getDefaultTracker() { if (mTracker == null) { this.analytics = GoogleAnalytics.getInstance(this); - analytics.getInstance(this).setLocalDispatchPeriod(1); + GoogleAnalytics.getInstance(this).setLocalDispatchPeriod(1); // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG mTracker = analytics.newTracker(0x7f070000); mTracker.enableAutoActivityTracking(true); diff --git a/app/src/main/res/layout/prompt_hostname_view.xml b/app/src/main/res/layout/prompt_hostname_view.xml new file mode 100644 index 0000000..605e94a --- /dev/null +++ b/app/src/main/res/layout/prompt_hostname_view.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/release/res/values/strings.xml b/app/src/release/res/values/strings.xml deleted file mode 100644 index 30ae030..0000000 --- a/app/src/release/res/values/strings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - http://192.168.0.33:8080 - \ No newline at end of file diff --git a/app/src/main/res/xml/network_security_config.xml b/app/src/release/res/xml/network_secure_config.xml similarity index 81% rename from app/src/main/res/xml/network_security_config.xml rename to app/src/release/res/xml/network_secure_config.xml index 65d70a3..636e8f0 100644 --- a/app/src/main/res/xml/network_security_config.xml +++ b/app/src/release/res/xml/network_secure_config.xml @@ -3,6 +3,5 @@ sodep.com.py - 192.168.0.33 \ No newline at end of file From e21132b63794419167d3796a5dbc11eb325bb0e7 Mon Sep 17 00:00:00 2001 From: Gonzalo Galeano Date: Wed, 2 Jun 2021 08:31:21 -0400 Subject: [PATCH 8/8] Update README.md --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 6eb0fc0..fa25554 100644 --- a/README.md +++ b/README.md @@ -103,11 +103,3 @@ Para cambiar a cualquier login JWT, se deben cambiar algunos parametros en login - url: Esta debe apuntar al servidor que se desea consultar. Ubicado en app/src/main/res/values/strings.xml como jwt_URL. - jsonRequest: Debe contener los datos necesarios para el servidor. En este caso se utilizaron solo 2 campos, username y password. - listener y errorListener: Aca se definen las acciones a tomar ya sea esperando una respuesta positiva, negativa o un error. - -## Configurar Entorno de Desarrollo - -Configurar el nombre de servidor en los siguientes archivos: - -app/src/main/res/xml/network_security_config.xml ( etiqueta: domain ) - -app/src/debug/res/values/strings.xml (host_name)