mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-01 05:07:40 +00:00
Merge pull request #3579 from keymanapp/fix/android/disable-install-button
fix(android/app): Validate language selection for "INSTALL" button
This commit is contained in:
commit
f45ebc3157
7 changed files with 68 additions and 58 deletions
|
|
@ -120,7 +120,7 @@ public class PackageActivity extends AppCompatActivity implements
|
|||
boolean isInstallingPackage = true;
|
||||
mStepperLayout = (StepperLayout) findViewById(R.id.stepperLayout);
|
||||
mStepperAdapter = new StepperAdapter(getSupportFragmentManager(), this,
|
||||
isInstallingPackage, tempPackagePath, pkgTarget, pkgId, pkgName, hasWelcome, languageID, languageCount);
|
||||
isInstallingPackage, tempPackagePath, pkgTarget, pkgId, pkgName, null, hasWelcome, languageID, languageCount);
|
||||
mStepperLayout.setAdapter(mStepperAdapter);
|
||||
mStepperLayout.setListener(this);
|
||||
}
|
||||
|
|
@ -178,7 +178,7 @@ public class PackageActivity extends AppCompatActivity implements
|
|||
|
||||
@Override
|
||||
public void onError(VerificationError verificationError) {
|
||||
Toast.makeText(this, "onError" + verificationError.getErrorMessage(), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this, verificationError.getErrorMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class SelectLanguageActivity extends AppCompatActivity implements
|
|||
|
||||
mStepperLayout = (StepperLayout) findViewById(R.id.stepperLayout);
|
||||
mStepperAdapter = new StepperAdapter(getSupportFragmentManager(), this,
|
||||
isInstallingPackage, packagePath, pkgTarget, packageID, pkgName, hasWelcome);
|
||||
isInstallingPackage, packagePath, pkgTarget, packageID, pkgName, keyboard, hasWelcome);
|
||||
mStepperLayout.setAdapter(mStepperAdapter);
|
||||
mStepperLayout.setListener(this);
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ public class SelectLanguageActivity extends AppCompatActivity implements
|
|||
|
||||
@Override
|
||||
public void onError(VerificationError verificationError) {
|
||||
Toast.makeText(this, "onError" + verificationError.getErrorMessage(), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this, verificationError.getErrorMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import androidx.fragment.app.Fragment;
|
|||
import com.stepstone.stepper.BlockingStep;
|
||||
import com.stepstone.stepper.StepperLayout;
|
||||
import com.stepstone.stepper.VerificationError;
|
||||
import com.tavultesoft.kmea.KMManager;
|
||||
import com.tavultesoft.kmea.data.Keyboard;
|
||||
import com.tavultesoft.kmea.data.KeyboardController;
|
||||
import com.tavultesoft.kmea.packages.PackageProcessor;
|
||||
|
|
@ -54,8 +53,10 @@ public final class SelectLanguageFragment extends Fragment implements BlockingSt
|
|||
private static final boolean excludeInstalledLanguages = false;
|
||||
private static String packageID = null;
|
||||
private static String languageID = null;
|
||||
private ArrayList<String> languageList = null;
|
||||
private ArrayList<Keyboard> addKeyboardsList = null;
|
||||
private ArrayList<String> languageList = new ArrayList<String>();
|
||||
private ArrayList<Keyboard> addKeyboardsList = new ArrayList<Keyboard>();
|
||||
private String title_no_install = null;
|
||||
private TextView textView;
|
||||
private File packagePath;
|
||||
private OnLanguagesSelectedListener callback;
|
||||
|
||||
|
|
@ -97,8 +98,6 @@ public final class SelectLanguageFragment extends Fragment implements BlockingSt
|
|||
packagePath = (File)bundle.getSerializable("packagePath");
|
||||
packageID = bundle.getString("packageID");
|
||||
languageID = bundle.getString("languageID");
|
||||
// Initialize the list of selected languages
|
||||
languageList = new ArrayList<String>();
|
||||
|
||||
JSONObject pkgInfo = kmpProcessor.loadPackageInfo(packagePath);
|
||||
Keyboard keyboard = bundle.containsKey("keyboard") ? (Keyboard)bundle.getSerializable("keyboard") :
|
||||
|
|
@ -110,7 +109,7 @@ public final class SelectLanguageFragment extends Fragment implements BlockingSt
|
|||
final String keyboardID = keyboard.getKeyboardID();
|
||||
final String keyboardName = keyboard.getKeyboardName();
|
||||
String title_install = String.format(getString(R.string.title_select_languages_for_package), keyboardName);
|
||||
String title_no_install = getString(R.string.all_languages_installed);
|
||||
title_no_install = getString(R.string.all_languages_installed);
|
||||
|
||||
final Toolbar toolbar = v.findViewById(R.id.list_toolbar);
|
||||
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
|
||||
|
|
@ -132,14 +131,12 @@ public final class SelectLanguageFragment extends Fragment implements BlockingSt
|
|||
}
|
||||
}
|
||||
|
||||
final TextView textView = v.findViewById(R.id.bar_title);
|
||||
textView = v.findViewById(R.id.bar_title);
|
||||
textView.setText(title_no_install);
|
||||
if (titleFont != null) {
|
||||
textView.setTypeface(titleFont, Typeface.BOLD);
|
||||
}
|
||||
|
||||
addKeyboardsList = new ArrayList<Keyboard>();
|
||||
|
||||
List<Keyboard> availableKeyboardsList = kmpProcessor.getKeyboardList(
|
||||
pkgInfo, packageID, keyboardID, isInstallingPackage, excludeInstalledLanguages);
|
||||
int position = KeyboardController.INDEX_NOT_FOUND;
|
||||
|
|
@ -218,12 +215,43 @@ public final class SelectLanguageFragment extends Fragment implements BlockingSt
|
|||
addKeyboardsList.add(k);
|
||||
}
|
||||
}
|
||||
|
||||
// Disable install button if no languages selected or all languages already installed
|
||||
checkLanguages();
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a language has been selected in the "Select Language" step.
|
||||
* Also enables/disables "NEXT" button accordingly.
|
||||
* @return VerificationError
|
||||
*/
|
||||
public VerificationError checkLanguages() {
|
||||
StepperLayout mStepperLayout = (StepperLayout) getActivity().findViewById(R.id.stepperLayout);
|
||||
|
||||
// Only applies if stepper is in "Select Language" step
|
||||
if ((isInstallingPackage && mStepperLayout.getCurrentStepPosition() == 1) ||
|
||||
(!isInstallingPackage && mStepperLayout.getCurrentStepPosition() == 0)) {
|
||||
// Two scenarios to disable "NEXT" button
|
||||
if (title_no_install != null && textView.getText().equals(title_no_install)) {
|
||||
mStepperLayout.setNextButtonVerificationFailed(true);
|
||||
return new VerificationError("All languages already installed");
|
||||
} else if (languageList.size() == 0 && addKeyboardsList.size() == 0) {
|
||||
mStepperLayout.setNextButtonVerificationFailed(true);
|
||||
return new VerificationError("No languages selected");
|
||||
} else {
|
||||
mStepperLayout.setNextButtonVerificationFailed(false);
|
||||
}
|
||||
} else {
|
||||
mStepperLayout.setNextButtonVerificationFailed(false);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNextClicked(final StepperLayout.OnNextClickedCallback callback) {
|
||||
// Send data to calling Activity
|
||||
|
|
@ -251,16 +279,24 @@ public final class SelectLanguageFragment extends Fragment implements BlockingSt
|
|||
@Override
|
||||
public void onBackClicked(StepperLayout.OnBackClickedCallback callback) {
|
||||
callback.goToPrevStep();
|
||||
|
||||
// Re-enable "NEXT" button
|
||||
StepperLayout mStepperLayout = (StepperLayout) getActivity().findViewById(R.id.stepperLayout);
|
||||
mStepperLayout.setNextButtonVerificationFailed(false);
|
||||
}
|
||||
@Override
|
||||
public VerificationError verifyStep() {
|
||||
return null;
|
||||
return checkLanguages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelected() {
|
||||
checkLanguages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull VerificationError error) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,11 +47,13 @@ public class StepperAdapter extends AbstractFragmentStepAdapter {
|
|||
* @param pkgTarget
|
||||
* @param packageID
|
||||
* @param pkgName
|
||||
* @param keyboard
|
||||
* @param hasWelcome
|
||||
*/
|
||||
public StepperAdapter(FragmentManager fm, Context context,
|
||||
boolean isInstallingPackage, File tempPackagePath,
|
||||
String pkgTarget, String packageID, String pkgName,
|
||||
Keyboard keyboard,
|
||||
boolean hasWelcome) {
|
||||
super(fm, context);
|
||||
this.isInstallingPackage = isInstallingPackage;
|
||||
|
|
@ -59,6 +61,7 @@ public class StepperAdapter extends AbstractFragmentStepAdapter {
|
|||
this.pkgTarget = pkgTarget;
|
||||
this.packageID = packageID;
|
||||
this.pkgName = pkgName;
|
||||
this.keyboard = keyboard;
|
||||
this.hasWelcome = hasWelcome;
|
||||
this.languageID = null; // not filled
|
||||
this.languageCount = 0;
|
||||
|
|
@ -67,6 +70,7 @@ public class StepperAdapter extends AbstractFragmentStepAdapter {
|
|||
public StepperAdapter(FragmentManager fm, Context context,
|
||||
boolean isInstallingPackage, File tempPackagePath,
|
||||
String pkgTarget, String packageID, String pkgName,
|
||||
Keyboard keyboard,
|
||||
boolean hasWelcome,
|
||||
String languageID, int languageCount) {
|
||||
super(fm, context);
|
||||
|
|
@ -75,6 +79,7 @@ public class StepperAdapter extends AbstractFragmentStepAdapter {
|
|||
this.pkgTarget = pkgTarget;
|
||||
this.packageID = packageID;
|
||||
this.pkgName = pkgName;
|
||||
this.keyboard = keyboard;
|
||||
this.hasWelcome = hasWelcome;
|
||||
this.languageID = languageID;
|
||||
this.languageCount = languageCount;
|
||||
|
|
@ -95,6 +100,9 @@ public class StepperAdapter extends AbstractFragmentStepAdapter {
|
|||
b1.putSerializable("packagePath", tempPackagePath);
|
||||
b1.putString("packageID", packageID);
|
||||
b1.putString("languageID", languageID);
|
||||
if (keyboard != null) {
|
||||
b1.putSerializable("keyboard", keyboard);
|
||||
}
|
||||
step1.setArguments(b1);
|
||||
return step1;
|
||||
}
|
||||
|
|
@ -107,6 +115,9 @@ public class StepperAdapter extends AbstractFragmentStepAdapter {
|
|||
b2.putSerializable("packagePath", tempPackagePath);
|
||||
b2.putString("packageID", packageID);
|
||||
b2.putString("languageID", languageID);
|
||||
if (keyboard != null) {
|
||||
b2.putSerializable("keyboard", keyboard);
|
||||
}
|
||||
step2.setArguments(b2);
|
||||
return step2;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item app:state_verification_failed="true" android:color="@color/neutral_3"/>
|
||||
<item android:color="@color/keyman_blue" />
|
||||
</selector>
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
app:ms_showBackButtonOnFirstStep="true"
|
||||
app:ms_backButtonColor="@color/keyman_blue"
|
||||
app:ms_backButtonText="@string/label_back"
|
||||
app:ms_nextButtonColor="@color/keyman_blue"
|
||||
app:ms_nextButtonColor="@color/ms_custom_button_text_color"
|
||||
app:ms_nextButtonText="@string/label_next"
|
||||
app:ms_completeButtonColor="@color/keyman_blue"
|
||||
app:ms_completeButtonText="@string/label_ok"
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/buttonBar"
|
||||
style="?android:attr/buttonBarStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/backButton"
|
||||
style="@style/Widget.AppCompat.Button.Borderless.Colored"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:drawableStart="@drawable/ic_action_back"
|
||||
android:text="@string/label_back"
|
||||
android:textColor="@color/keyman_blue" />
|
||||
|
||||
<!-- Spacer padding -->
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<!-- forwardButton will be one of OK / NEXT / INSTALL -->
|
||||
<Button
|
||||
android:id="@+id/forwardButton"
|
||||
style="@style/Widget.AppCompat.Button.Borderless.Colored"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:drawableEnd="@drawable/ic_action_forward"
|
||||
android:elevation="1dp"
|
||||
android:singleLine="true"
|
||||
android:text="@string/label_next"
|
||||
android:textColor="@color/keyman_blue">
|
||||
|
||||
<requestFocus />
|
||||
</Button>
|
||||
|
||||
</LinearLayout>
|
||||
Loading…
Add table
Reference in a new issue