Skip to content

Commit

Permalink
Merge pull request #2 from totvslabs/feature-default-fields
Browse files Browse the repository at this point in the history
Default values for app (scheme, name and id)
  • Loading branch information
Bruno Tortato Furtado authored Feb 25, 2019
2 parents 0b0e7b7 + 2a8c487 commit 28e7e54
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 11 deletions.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ android {
applicationId "ai.carol.deeplinking"
minSdkVersion 16
targetSdkVersion 28
versionCode 2
versionName "1.0.1"
versionCode 3
versionName "1.0.2"

def scheme = "deeplinking";
manifestPlaceholders = [scheme: "${scheme}"]
buildConfigField("String", "SCHEME", "\"${scheme}\"")
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -29,6 +33,7 @@ android {
}

ext {
scheme = "deeplinking"
androidVersion = "28.0.0"
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="deeplinking" android:host="clockin" />
<data android:scheme="${scheme}" android:host="clockin" />
</intent-filter>
</activity>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mEdtAppName.setText(DatabaseHelper.fetchAppName(context));
mEdtAppIdentifier.setText(DatabaseHelper.fetchAppIdentifier(context));

mEdtAppScheme.setEnabled(false);
mEdtAppName.setEnabled(false);
mEdtAppIdentifier.setEnabled(false);

mBtnSave.setOnClickListener((view) -> save());
}

Expand Down
16 changes: 13 additions & 3 deletions app/src/main/java/ai/carol/deeplinking/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Locale;

import ai.carol.deeplinking.R;
import ai.carol.deeplinking.helper.AlertHelper;
import ai.carol.deeplinking.helper.ConverterHelper;
import ai.carol.deeplinking.helper.DatabaseHelper;
import ai.carol.deeplinking.model.ClockInObject;
Expand Down Expand Up @@ -76,11 +77,20 @@ private void startEditActivity() {
}

private void startSendDataActivity() {
final String tenant = getString(mTxtTenant);
final String email = getString(mTxtEmail);
final String password = getString(mTxtPassword);

if (tenant.isEmpty() || email.isEmpty() || password.isEmpty()) {
AlertHelper.showFillFieldsAlert(this);
return;
}

final Intent sendDataIntent = new Intent(getBaseContext(), SendDataActivity.class);

sendDataIntent.putExtra(SendDataActivity.TENANT_EXTRA, getString(mTxtTenant));
sendDataIntent.putExtra(SendDataActivity.EMAIL_EXTRA, getString(mTxtEmail));
sendDataIntent.putExtra(SendDataActivity.PASSWORD_EXTRA, getString(mTxtPassword));
sendDataIntent.putExtra(SendDataActivity.TENANT_EXTRA, tenant);
sendDataIntent.putExtra(SendDataActivity.EMAIL_EXTRA, email);
sendDataIntent.putExtra(SendDataActivity.PASSWORD_EXTRA, password);
sendDataIntent.putExtra(SendDataActivity.APP_SCHEME_EXTRA, getString(mTxtAppScheme));
sendDataIntent.putExtra(SendDataActivity.APP_NAME_EXTRA, getString(mTxtAppName));
sendDataIntent.putExtra(SendDataActivity.APP_IDENTIFIER_EXTRA, getString(mTxtAppIdentifier));
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/ai/carol/deeplinking/helper/AlertHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.annotation.NonNull;

import ai.carol.deeplinking.R;
import ai.carol.deeplinking.activity.EditActivity;

public final class AlertHelper {

Expand All @@ -28,6 +29,15 @@ public static void showPlayStoreAlert(@NonNull final Activity activity) {
.show();
}

public static void showFillFieldsAlert(@NonNull final Activity activity) {
new AlertDialog.Builder(activity)
.setTitle(R.string.app_name)
.setMessage(R.string.fill_all_fields)
.setCancelable(false)
.setPositiveButton(R.string.yes_right_away, (dialog, which) -> openEditActivity(activity))
.show();
}

//endregion

//region - Private
Expand All @@ -42,6 +52,11 @@ private static void openPlayStorePage(@NonNull final Activity activity) {
}
}

private static void openEditActivity(@NonNull final Activity activity) {
final Intent editIntent = new Intent(activity, EditActivity.class);
activity.startActivity(editIntent);
}

//endregion

}
32 changes: 27 additions & 5 deletions app/src/main/java/ai/carol/deeplinking/helper/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import android.content.SharedPreferences;
import android.support.annotation.NonNull;

import ai.carol.deeplinking.BuildConfig;
import ai.carol.deeplinking.R;

public final class DatabaseHelper {

private static final String DB_NAME = "ai.carol.deeplinking.database";
Expand All @@ -22,21 +25,21 @@ public static void saveAppIdentifier(@NonNull final Context context, final Strin
save(context, APP_IDENTIFIER_KEY, appIdentifier);
}
public static String fetchAppIdentifier(@NonNull final Context context) {
return fetch(context, APP_IDENTIFIER_KEY);
return fetch(context, APP_IDENTIFIER_KEY, getAppIdentifierDefault());
}

public static void saveAppName(@NonNull final Context context, final String appName) {
save(context, APP_NAME_KEY, appName);
}
public static String fetchAppName(@NonNull final Context context) {
return fetch(context, APP_NAME_KEY);
return fetch(context, APP_NAME_KEY, getAppNameDefault(context));
}

public static void saveAppScheme(@NonNull final Context context, final String appScheme) {
save(context, APP_SCHEME_KEY, appScheme);
}
public static String fetchAppScheme(@NonNull final Context context) {
return fetch(context, APP_SCHEME_KEY);
return fetch(context, APP_SCHEME_KEY, getAppSchemeDefault(context));
}

public static void saveClockIns(@NonNull final Context context, final String clockIns) {
Expand Down Expand Up @@ -67,7 +70,7 @@ public static String fetchTenant(@NonNull final Context context) {
return fetch(context, TENANT_KEY);
}

//region - Private
//region - Private Helper

private static void save(@NonNull final Context context, @NonNull final String key, final String value) {
final SharedPreferences preferences = getPreferences(context);
Expand All @@ -78,8 +81,11 @@ private static void save(@NonNull final Context context, @NonNull final String k
}

private static String fetch(@NonNull final Context context, @NonNull final String key) {
return fetch(context, key, null);
}

private static String fetch(@NonNull final Context context, @NonNull final String key, final String defaultValue) {
final SharedPreferences preferences = getPreferences(context);
final String defaultValue = null;
return preferences.getString(key, defaultValue);
}

Expand All @@ -89,4 +95,20 @@ private static SharedPreferences getPreferences(@NonNull final Context context)

//endregion

//region - Private Default

private static String getAppIdentifierDefault() {
return BuildConfig.APPLICATION_ID;
}

private static String getAppNameDefault(final @NonNull Context context) {
return context.getString(R.string.app_name);
}

private static String getAppSchemeDefault(final @NonNull Context context) {
return BuildConfig.SCHEME;
}

//endregion

}
2 changes: 2 additions & 0 deletions app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
<string name="data_to_send">Dados a serem enviados</string>
<string name="edit">Editar dados a serem enviados</string>
<string name="email">E-mail:\u0020</string>
<string name="fill_all_fields">Preencha todos os campos para continuar.</string>
<string name="go_to_clock_in">Logar no Clock-In</string>
<string name="password">Senha:\u0020</string>
<string name="reset">Limpar</string>
<string name="received_data">Dados recebidos</string>
<string name="save">Salvar</string>
<string name="tenant">Tenant:\u0020</string>
<string name="yes_install">Sim, instalar</string>
<string name="yes_right_away">Sim, é pra já!</string>
<string name="want_to_install_clock_in">Deseja instalar o app Clock-In?</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
<string name="data_to_send">Data to Send</string>
<string name="edit">Edit Data to Send</string>
<string name="email">Email:\u0020</string>
<string name="fill_all_fields">Fill all the fields to continue.</string>
<string name="go_to_clock_in">Login into Clock-In</string>
<string name="password">Password:\u0020</string>
<string name="reset">Reset</string>
<string name="received_data">Received Data</string>
<string name="save">Save</string>
<string name="tenant">Tenant:\u0020</string>
<string name="yes_install">Yes, install</string>
<string name="yes_right_away">Yes, right away!</string>
<string name="want_to_install_clock_in">Do you want to install the Clock-In app?</string>
</resources>

0 comments on commit 28e7e54

Please sign in to comment.