Fix lint issues
This commit is contained in:
@@ -44,27 +44,27 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Singleton
|
||||
public class VariablesRegistry extends BaseEntitiesRegistry<IConstant> {
|
||||
|
||||
@Nonnull
|
||||
private static final Map<String, String> substitutes = new HashMap<>();
|
||||
|
||||
static {
|
||||
substitutes.put("π", "pi");
|
||||
substitutes.put("Π", "PI");
|
||||
substitutes.put("∞", "inf");
|
||||
substitutes.put("h", "h_reduced");
|
||||
substitutes.put("NaN", "nan");
|
||||
{
|
||||
addDescription("Π", R.string.c_var_description_PI);
|
||||
addDescription("π", R.string.c_var_description_pi);
|
||||
addDescription("e", R.string.c_var_description_e);
|
||||
addDescription("i", R.string.c_var_description_i);
|
||||
addDescription("c", R.string.c_var_description_c);
|
||||
addDescription("G", R.string.c_var_description_G);
|
||||
addDescription("h", R.string.c_var_description_h_reduced);
|
||||
addDescription("∞", R.string.c_var_description_inf);
|
||||
addDescription("inf", R.string.c_var_description_inf);
|
||||
addDescription("nan", R.string.c_var_description_nan);
|
||||
addDescription("NaN", R.string.c_var_description_nan);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public VariablesRegistry(@Nonnull JsclMathEngine mathEngine) {
|
||||
super(mathEngine.getConstantsRegistry(), "c_var_description_");
|
||||
super(mathEngine.getConstantsRegistry());
|
||||
}
|
||||
|
||||
public void addOrUpdate(@Nonnull IConstant newVariable, @Nullable IConstant oldVariable) {
|
||||
@@ -82,12 +82,6 @@ public class VariablesRegistry extends BaseEntitiesRegistry<IConstant> {
|
||||
bus.post(new RemovedEvent(variable));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected Map<String, String> getSubstitutes() {
|
||||
return substitutes;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
Check.isNotMainThread();
|
||||
|
||||
|
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.about;
|
||||
|
||||
import android.content.res.Resources;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 4/20/12
|
||||
* Time: 3:31 PM
|
||||
*/
|
||||
public class TextHelper {
|
||||
|
||||
@Nonnull
|
||||
public String packageName;
|
||||
|
||||
@Nonnull
|
||||
public Resources resources;
|
||||
|
||||
public TextHelper(@Nonnull Resources resources, @Nonnull String packageName) {
|
||||
this.packageName = packageName;
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getText(@Nonnull String stringName) {
|
||||
final int stringId = this.resources.getIdentifier(stringName, "string", this.packageName);
|
||||
try {
|
||||
if (stringId == 0) {
|
||||
return null;
|
||||
}
|
||||
return resources.getString(stringId);
|
||||
} catch (Resources.NotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -390,7 +390,7 @@ public class ConverterFragment extends BaseDialogFragment
|
||||
ELECTRIC_CURRENT(Dimension.ELECTRIC_CURRENT, R.string.cpp_converter_electric_current),
|
||||
LENGTH(Dimension.LENGTH, R.string.cpp_converter_length),
|
||||
MASS(Dimension.MASS, R.string.cpp_converter_mass),
|
||||
TEMPERATURE(Dimension.TEMPERATURE, R.string.cpp_converter_termperature);
|
||||
TEMPERATURE(Dimension.TEMPERATURE, R.string.cpp_converter_temperature);
|
||||
|
||||
@NonNull
|
||||
public final Dimension dimension;
|
||||
|
@@ -23,16 +23,17 @@
|
||||
package org.solovyev.android.calculator.entities;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringRes;
|
||||
import com.squareup.otto.Bus;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.solovyev.android.Check;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.AppModule;
|
||||
import org.solovyev.android.calculator.EntitiesRegistry;
|
||||
import org.solovyev.android.calculator.ErrorReporter;
|
||||
import org.solovyev.android.calculator.json.Json;
|
||||
import org.solovyev.android.calculator.json.Jsonable;
|
||||
import org.solovyev.android.io.FileSaver;
|
||||
@@ -46,10 +47,7 @@ import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public abstract class BaseEntitiesRegistry<T extends MathEntity> implements EntitiesRegistry<T> {
|
||||
@@ -58,8 +56,6 @@ public abstract class BaseEntitiesRegistry<T extends MathEntity> implements Enti
|
||||
protected final Object lock = this;
|
||||
@Nonnull
|
||||
private final MathRegistry<T> mathRegistry;
|
||||
@Nonnull
|
||||
private final String prefix;
|
||||
@NonNull
|
||||
private final WriteTask writeTask = new WriteTask();
|
||||
@Inject
|
||||
@@ -81,33 +77,29 @@ public abstract class BaseEntitiesRegistry<T extends MathEntity> implements Enti
|
||||
@Named(AppModule.DIR_FILES)
|
||||
public File filesDir;
|
||||
|
||||
@Nonnull
|
||||
private final Map<String, Integer> descriptions = new HashMap<>();
|
||||
|
||||
// synchronized on lock
|
||||
private boolean initialized;
|
||||
|
||||
protected BaseEntitiesRegistry(@Nonnull MathRegistry<T> mathRegistry,
|
||||
@Nonnull String prefix) {
|
||||
protected BaseEntitiesRegistry(@Nonnull MathRegistry<T> mathRegistry) {
|
||||
this.mathRegistry = mathRegistry;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
protected abstract Map<String, String> getSubstitutes();
|
||||
protected void addDescription(@Nonnull String name, @StringRes int description) {
|
||||
descriptions.put(name, description);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getDescription(@Nonnull String name) {
|
||||
final String stringName;
|
||||
|
||||
final Map<String, String> substitutes = getSubstitutes();
|
||||
final String substitute = substitutes.get(name);
|
||||
if (substitute == null) {
|
||||
stringName = prefix + name;
|
||||
} else {
|
||||
stringName = prefix + substitute;
|
||||
final Integer description = descriptions.get(name);
|
||||
if (description == null || description == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getDescription(application, stringName);
|
||||
return application.getResources().getString(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,18 +107,6 @@ public abstract class BaseEntitiesRegistry<T extends MathEntity> implements Enti
|
||||
setInitialized();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getDescription(@Nonnull Context context, @Nonnull String descriptionId) {
|
||||
final Resources resources = context.getResources();
|
||||
|
||||
final int stringId = resources.getIdentifier(descriptionId, "string", CalculatorApplication.class.getPackage().getName());
|
||||
try {
|
||||
return resources.getString(stringId);
|
||||
} catch (Resources.NotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected final <E> List<E> loadEntities(@NonNull Json.Creator<E> creator) {
|
||||
final File file = getEntitiesFile();
|
||||
|
@@ -30,6 +30,7 @@ import jscl.math.function.IFunction;
|
||||
import org.simpleframework.xml.Serializer;
|
||||
import org.simpleframework.xml.core.Persister;
|
||||
import org.solovyev.android.Check;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.entities.BaseEntitiesRegistry;
|
||||
import org.solovyev.android.calculator.entities.Category;
|
||||
import org.solovyev.android.calculator.entities.Entities;
|
||||
@@ -43,23 +44,47 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static android.text.TextUtils.isEmpty;
|
||||
|
||||
@Singleton
|
||||
public class FunctionsRegistry extends BaseEntitiesRegistry<Function> {
|
||||
|
||||
@Nonnull
|
||||
private static final Map<String, String> substitutes = new HashMap<>();
|
||||
|
||||
static {
|
||||
substitutes.put("√", "sqrt");
|
||||
{
|
||||
addDescription("sin", R.string.c_fun_description_sin);
|
||||
addDescription("cos", R.string.c_fun_description_cos);
|
||||
addDescription("tan", R.string.c_fun_description_tan);
|
||||
addDescription("cot", R.string.c_fun_description_cot);
|
||||
addDescription("asin", R.string.c_fun_description_asin);
|
||||
addDescription("acos", R.string.c_fun_description_acos);
|
||||
addDescription("atan", R.string.c_fun_description_atan);
|
||||
addDescription("acot", R.string.c_fun_description_acot);
|
||||
addDescription("ln", R.string.c_fun_description_ln);
|
||||
addDescription("lg", R.string.c_fun_description_lg);
|
||||
addDescription("log", R.string.c_fun_description_log);
|
||||
addDescription("exp", R.string.c_fun_description_exp);
|
||||
addDescription("√", R.string.c_fun_description_sqrt);
|
||||
addDescription("sqrt", R.string.c_fun_description_sqrt);
|
||||
addDescription("cubic", R.string.c_fun_description_cubic);
|
||||
addDescription("abs", R.string.c_fun_description_abs);
|
||||
addDescription("sgn", R.string.c_fun_description_sgn);
|
||||
addDescription("eq", R.string.c_fun_description_eq);
|
||||
addDescription("le", R.string.c_fun_description_le);
|
||||
addDescription("ge", R.string.c_fun_description_ge);
|
||||
addDescription("ne", R.string.c_fun_description_ne);
|
||||
addDescription("lt", R.string.c_fun_description_lt);
|
||||
addDescription("gt", R.string.c_fun_description_gt);
|
||||
addDescription("rad", R.string.c_fun_description_rad);
|
||||
addDescription("dms", R.string.c_fun_description_dms);
|
||||
addDescription("deg", R.string.c_fun_description_deg);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public FunctionsRegistry(@Nonnull JsclMathEngine mathEngine) {
|
||||
super(mathEngine.getFunctionsRegistry(), "c_fun_description_");
|
||||
super(mathEngine.getFunctionsRegistry());
|
||||
}
|
||||
|
||||
public void addOrUpdate(@Nonnull Function newFunction, @Nullable Function oldFunction) {
|
||||
@@ -91,6 +116,7 @@ public class FunctionsRegistry extends BaseEntitiesRegistry<Function> {
|
||||
setInitialized();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Function addSafely(@Nonnull CustomFunction.Builder builder) {
|
||||
try {
|
||||
@@ -141,12 +167,6 @@ public class FunctionsRegistry extends BaseEntitiesRegistry<Function> {
|
||||
return new File(filesDir, "functions.json");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected Map<String, String> getSubstitutes() {
|
||||
return substitutes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Category getCategory(@Nonnull Function function) {
|
||||
return Entities.getCategory(function, FunctionCategory.values());
|
||||
|
@@ -25,6 +25,7 @@ package org.solovyev.android.calculator.operators;
|
||||
import android.support.annotation.NonNull;
|
||||
import jscl.JsclMathEngine;
|
||||
import jscl.math.operator.Operator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.entities.BaseEntitiesRegistry;
|
||||
import org.solovyev.android.calculator.entities.Category;
|
||||
import org.solovyev.android.calculator.entities.Entities;
|
||||
@@ -35,33 +36,23 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Singleton
|
||||
public class OperatorsRegistry extends BaseEntitiesRegistry<Operator> {
|
||||
|
||||
@Nonnull
|
||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||
|
||||
static {
|
||||
substitutes.put("Σ", "sum");
|
||||
substitutes.put("∏", "product");
|
||||
substitutes.put("∂", "derivative");
|
||||
substitutes.put("∫ab", "integral_ab");
|
||||
substitutes.put("∫", "integral");
|
||||
substitutes.put("Σ", "sum");
|
||||
{
|
||||
addDescription("mod", R.string.c_op_description_mod);
|
||||
addDescription("Σ", R.string.c_op_description_sum);
|
||||
addDescription("∏", R.string.c_op_description_product);
|
||||
addDescription("∂", R.string.c_op_description_derivative);
|
||||
addDescription("∫ab", R.string.c_op_description_integral_ab);
|
||||
addDescription("∫", R.string.c_op_description_integral);
|
||||
addDescription("Σ", R.string.c_op_description_sum);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public OperatorsRegistry(@Nonnull JsclMathEngine mathEngine) {
|
||||
super(mathEngine.getOperatorsRegistry(), "c_op_description_");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected Map<String, String> getSubstitutes() {
|
||||
return substitutes;
|
||||
super(mathEngine.getOperatorsRegistry());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@@ -25,6 +25,7 @@ package org.solovyev.android.calculator.operators;
|
||||
import android.support.annotation.NonNull;
|
||||
import jscl.JsclMathEngine;
|
||||
import jscl.math.operator.Operator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.entities.BaseEntitiesRegistry;
|
||||
import org.solovyev.android.calculator.entities.Category;
|
||||
import org.solovyev.android.calculator.entities.Entities;
|
||||
@@ -35,31 +36,20 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Singleton
|
||||
public class PostfixFunctionsRegistry extends BaseEntitiesRegistry<Operator> {
|
||||
|
||||
@Nonnull
|
||||
private static final Map<String, String> substitutes = new HashMap<String, String>();
|
||||
|
||||
static {
|
||||
substitutes.put("%", "percent");
|
||||
substitutes.put("!", "factorial");
|
||||
substitutes.put("!!", "double_factorial");
|
||||
substitutes.put("°", "degree");
|
||||
{
|
||||
addDescription("%", R.string.c_pf_description_percent);
|
||||
addDescription("!", R.string.c_pf_description_factorial);
|
||||
addDescription("!!", R.string.c_pf_description_double_factorial);
|
||||
addDescription("°", R.string.c_pf_description_degree);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public PostfixFunctionsRegistry(@Nonnull JsclMathEngine mathEngine) {
|
||||
super(mathEngine.getPostfixFunctionsRegistry(), "c_pf_description_");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected Map<String, String> getSubstitutes() {
|
||||
return substitutes;
|
||||
super(mathEngine.getPostfixFunctionsRegistry());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package org.solovyev.android.calculator.release;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
public class ReleaseNote {
|
||||
@NonNull
|
||||
public final String versionName;
|
||||
@StringRes
|
||||
public final int description;
|
||||
|
||||
private ReleaseNote(@NonNull String versionName, int description) {
|
||||
this.versionName = versionName;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ReleaseNote make(@NonNull String versionName, int description) {
|
||||
return new ReleaseNote(versionName, description);
|
||||
}
|
||||
}
|
@@ -6,12 +6,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.TextHelper;
|
||||
import org.solovyev.android.calculator.wizard.WizardFragment;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -33,25 +28,14 @@ public class ReleaseNoteFragment extends WizardFragment {
|
||||
version = getArguments().getInt(ARG_VERSION, 0);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
final TextView title = (TextView) view.findViewById(R.id.release_note_title);
|
||||
final TextHelper textHelper = new TextHelper(getActivity().getResources(), CalculatorApplication.class.getPackage().getName());
|
||||
title.setText(getString(R.string.cpp_new_in_version, getReleaseNoteVersion(textHelper)));
|
||||
title.setText(getString(R.string.cpp_new_in_version, ReleaseNotes.getReleaseNoteVersion(version)));
|
||||
final TextView message = (TextView) view.findViewById(R.id.release_note_message);
|
||||
message.setText(Html.fromHtml(getReleaseNote(textHelper)));
|
||||
message.setText(Html.fromHtml(ReleaseNotes.getReleaseNoteDescription(getActivity(), version)));
|
||||
return view;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private String getReleaseNoteVersion(@Nonnull TextHelper textHelper) {
|
||||
return ReleaseNotes.getVersionName(textHelper, version);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private String getReleaseNote(@Nonnull TextHelper textHelper) {
|
||||
final String resourceId = ReleaseNotes.makeReleaseNotesResourceId(version);
|
||||
return Strings.nullToEmpty(textHelper.getText(resourceId)).replace("\n", "<br/>");
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,9 @@
|
||||
package org.solovyev.android.calculator.release;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.SparseArray;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.about.TextHelper;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -13,11 +12,30 @@ import java.util.List;
|
||||
|
||||
public final class ReleaseNotes {
|
||||
|
||||
private static final SparseArray<ReleaseNote> map = new SparseArray<>();
|
||||
static {
|
||||
map.put(118, ReleaseNote.make("2.0.0", R.string.c_release_notes_for_118));
|
||||
map.put(141, ReleaseNote.make("2.1.2", R.string.c_release_notes_for_141));
|
||||
map.put(143, ReleaseNote.make("2.1.4", R.string.c_release_notes_for_143));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static String getReleaseNotes(@Nonnull Context context) {
|
||||
return getReleaseNotesString(context, 0);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static String getReleaseNoteVersion(int version) {
|
||||
final ReleaseNote releaseNote = map.get(version);
|
||||
return releaseNote == null ? String.valueOf(version) : releaseNote.versionName;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static String getReleaseNoteDescription(@Nonnull Context context, int version) {
|
||||
final ReleaseNote releaseNote = map.get(version);
|
||||
return releaseNote == null ? "" : context.getString(releaseNote.description);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static String getReleaseNotesString(@Nonnull Context context, int minVersion) {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
@@ -25,22 +43,21 @@ public final class ReleaseNotes {
|
||||
final String releaseNotesForTitle = context.getString(R.string.c_release_notes_for_title);
|
||||
final int currentVersionCode = App.getAppVersionCode(context);
|
||||
|
||||
final TextHelper textHelper = new TextHelper(context.getResources(), CalculatorApplication.class.getPackage().getName());
|
||||
|
||||
boolean first = true;
|
||||
for (int versionCode = currentVersionCode; versionCode >= minVersion; versionCode--) {
|
||||
final String versionName = getVersionName(textHelper, versionCode);
|
||||
String releaseNotesForVersion = textHelper.getText(makeReleaseNotesResourceId(versionCode));
|
||||
if (!Strings.isEmpty(releaseNotesForVersion)) {
|
||||
if (!first) {
|
||||
result.append("<br/><br/>");
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
releaseNotesForVersion = releaseNotesForVersion.replace("\n", "<br/>");
|
||||
result.append("<b>").append(releaseNotesForTitle).append(versionName).append("</b><br/><br/>");
|
||||
result.append(releaseNotesForVersion);
|
||||
final ReleaseNote releaseNote = map.get(versionCode);
|
||||
if (releaseNote == null) {
|
||||
continue;
|
||||
}
|
||||
if (!first) {
|
||||
result.append("<br/><br/>");
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
final String description = context.getResources().getString(releaseNote.description);
|
||||
final String descriptionHtml = description.replace("\n", "<br/>");
|
||||
result.append("<b>").append(releaseNotesForTitle).append(releaseNote.versionName).append("</b><br/><br/>");
|
||||
result.append(descriptionHtml);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
@@ -51,14 +68,17 @@ public final class ReleaseNotes {
|
||||
final List<Integer> releaseNotes = new ArrayList<>();
|
||||
|
||||
final int currentVersionCode = App.getAppVersionCode(context);
|
||||
final TextHelper textHelper = new TextHelper(context.getResources(), CalculatorApplication.class.getPackage().getName());
|
||||
|
||||
for (int versionCode = currentVersionCode; versionCode >= minVersion; versionCode--) {
|
||||
if (versionCode == ChooseThemeReleaseNoteStep.VERSION_CODE) {
|
||||
releaseNotes.add(ChooseThemeReleaseNoteStep.VERSION_CODE);
|
||||
}
|
||||
final String releaseNotesForVersion = textHelper.getText(makeReleaseNotesResourceId(versionCode));
|
||||
if (!Strings.isEmpty(releaseNotesForVersion)) {
|
||||
final ReleaseNote releaseNote = map.get(versionCode);
|
||||
if (releaseNote == null) {
|
||||
continue;
|
||||
}
|
||||
final String description = context.getString(releaseNote.description);
|
||||
if (!Strings.isEmpty(description)) {
|
||||
releaseNotes.add(versionCode);
|
||||
}
|
||||
}
|
||||
@@ -68,36 +88,20 @@ public final class ReleaseNotes {
|
||||
|
||||
public static boolean hasReleaseNotes(@Nonnull Context context, int minVersion) {
|
||||
final int currentVersionCode = App.getAppVersionCode(context);
|
||||
final TextHelper textHelper = new TextHelper(context.getResources(), CalculatorApplication.class.getPackage().getName());
|
||||
|
||||
for (int versionCode = currentVersionCode; versionCode >= minVersion; versionCode--) {
|
||||
if (versionCode == ChooseThemeReleaseNoteStep.VERSION_CODE) {
|
||||
return true;
|
||||
}
|
||||
String releaseNotesForVersion = textHelper.getText(makeReleaseNotesResourceId(versionCode));
|
||||
if (!Strings.isEmpty(releaseNotesForVersion)) {
|
||||
final ReleaseNote releaseNote = map.get(versionCode);
|
||||
if (releaseNote == null) {
|
||||
continue;
|
||||
}
|
||||
if (!Strings.isEmpty(context.getString(releaseNote.description))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static String getVersionName(@Nonnull TextHelper textHelper, int versionCode) {
|
||||
final String versionName = textHelper.getText(makeVersionResourceId(versionCode));
|
||||
if (versionName != null) {
|
||||
return versionName;
|
||||
} else {
|
||||
return String.valueOf(versionCode);
|
||||
}
|
||||
}
|
||||
|
||||
public static String makeReleaseNotesResourceId(int versionCode) {
|
||||
return "c_release_notes_for_" + versionCode;
|
||||
}
|
||||
|
||||
private static String makeVersionResourceId(int versionCode) {
|
||||
return "c_release_notes_for_" + versionCode + "_version";
|
||||
}
|
||||
}
|
||||
|
@@ -31,6 +31,8 @@ import android.widget.TextView;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class WelcomeWizardStep extends WizardFragment {
|
||||
|
||||
@Override
|
||||
@@ -38,6 +40,7 @@ public final class WelcomeWizardStep extends WizardFragment {
|
||||
return R.layout.cpp_wizard_step_welcome;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
@@ -68,6 +68,7 @@ public abstract class WizardFragment extends Fragment implements View.OnClickLis
|
||||
throw new AssertionError("Wizard step for class " + getClass() + " was not found");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View view = inflater.inflate(R.layout.fragment_wizard, container, false);
|
||||
|
@@ -22,6 +22,8 @@
|
||||
|
||||
package org.solovyev.common.text;
|
||||
|
||||
import org.solovyev.android.Check;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
@@ -74,7 +76,7 @@ public class NumberMapper<N extends Number> implements Mapper<N> {
|
||||
|
||||
@Nonnull
|
||||
public static <N extends Number> Mapper<N> of(@Nonnull Class<? extends N> clazz) {
|
||||
assert supportedClasses.contains(clazz) : "Class " + clazz + " is not supported by " + NumberMapper.class;
|
||||
Check.isTrue(supportedClasses.contains(clazz), "Class " + clazz + " is not supported by " + NumberMapper.class);
|
||||
return (Mapper<N>) mappers.get(clazz);
|
||||
}
|
||||
|
||||
|
@@ -22,6 +22,8 @@
|
||||
|
||||
package org.solovyev.common.text;
|
||||
|
||||
import org.solovyev.android.Check;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
@@ -50,7 +52,7 @@ public class NumberParser<N extends Number> implements Parser<N> {
|
||||
|
||||
@Nonnull
|
||||
public static <N extends Number> Parser<N> of(@Nonnull Class<N> clazz) {
|
||||
assert supportedClasses.contains(clazz) : "Class " + clazz + " is not supported by " + NumberParser.class;
|
||||
Check.isTrue(supportedClasses.contains(clazz), "Class " + clazz + " is not supported by " + NumberParser.class);
|
||||
return (Parser<N>) parsers.get(clazz);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user