diff --git a/app/src/main/java/protect/card_locker/AboutActivity.java b/app/src/main/java/protect/card_locker/AboutActivity.java index da7002939..ca59bd18e 100644 --- a/app/src/main/java/protect/card_locker/AboutActivity.java +++ b/app/src/main/java/protect/card_locker/AboutActivity.java @@ -1,29 +1,12 @@ package protect.card_locker; -import android.content.ActivityNotFoundException; -import android.content.Intent; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.net.Uri; import android.os.Bundle; -import android.util.Log; import android.view.MenuItem; import android.view.View; import android.widget.TextView; -import android.widget.Toast; - -import androidx.collection.ArrayMap; -import androidx.core.text.HtmlCompat; import com.google.android.material.dialog.MaterialAlertDialogBuilder; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; import protect.card_locker.databinding.AboutActivityBinding; @@ -32,6 +15,7 @@ public class AboutActivity extends CatimaAppCompatActivity { private static final String TAG = "Catima"; private AboutActivityBinding binding; + private AboutContent content; @Override protected void onCreate(Bundle savedInstanceState) { @@ -42,11 +26,12 @@ public class AboutActivity extends CatimaAppCompatActivity { setSupportActionBar(binding.toolbar); enableToolbarBackButton(); + content = new AboutContent(this); TextView copyright = binding.creditsSub; - copyright.setText(String.format(getString(R.string.app_copyright_fmt), getCurrentYear())); + copyright.setText(String.format(getString(R.string.app_copyright_fmt), content.getCurrentYear())); TextView versionHistory = binding.versionHistorySub; - versionHistory.setText(String.format(getString(R.string.debug_version_fmt), getAppVersion())); + versionHistory.setText(String.format(getString(R.string.debug_version_fmt), content.getAppVersion())); bindClickListeners(); } @@ -63,6 +48,7 @@ public class AboutActivity extends CatimaAppCompatActivity { @Override protected void onDestroy() { super.onDestroy(); + content.destroy(); clearClickListeners(); binding = null; } @@ -81,7 +67,7 @@ public class AboutActivity extends CatimaAppCompatActivity { binding.credits .setOnClickListener(view -> new MaterialAlertDialogBuilder(this) .setTitle(R.string.credits) - .setMessage(getContributorInfo()) + .setMessage(content.getContributorInfo()) .setPositiveButton(R.string.ok, (dialogInterface, i) -> { }) .show()); @@ -97,85 +83,4 @@ public class AboutActivity extends CatimaAppCompatActivity { binding.rate.setOnClickListener(null); binding.credits.setOnClickListener(null); } - - private String getAppVersion() { - String version = "?"; - try { - PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0); - version = pi.versionName; - } catch (PackageManager.NameNotFoundException e) { - Log.w(TAG, "Package name not found", e); - } - - return version; - } - - private int getCurrentYear() { - return Calendar.getInstance().get(Calendar.YEAR); - } - - private String getContributors() { - StringBuilder contributors = new StringBuilder().append("
"); - - BufferedReader reader = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.contributors), StandardCharsets.UTF_8)); - - try { - while (true) { - String tmp = reader.readLine(); - - if (tmp == null || tmp.isEmpty()) { - reader.close(); - break; - } - - contributors.append("
"); - contributors.append(tmp); - } - } catch (IOException ignored) { - } - - return contributors.toString(); - } - - private String getThirdPartyLibraries() { - final List USED_LIBRARIES = new ArrayList<>(); - USED_LIBRARIES.add(new ThirdPartyInfo("Color Picker", "https://github.com/jaredrummler/ColorPicker", "Apache 2.0")); - USED_LIBRARIES.add(new ThirdPartyInfo("Commons CSV", "https://commons.apache.org/proper/commons-csv/", "Apache 2.0")); - USED_LIBRARIES.add(new ThirdPartyInfo("NumberPickerPreference", "https://github.com/invissvenska/NumberPickerPreference", "GNU LGPL 3.0")); - USED_LIBRARIES.add(new ThirdPartyInfo("uCrop", "https://github.com/Yalantis/uCrop", "Apache 2.0")); - USED_LIBRARIES.add(new ThirdPartyInfo("Zip4j", "https://github.com/srikanth-lingala/zip4j", "Apache 2.0")); - USED_LIBRARIES.add(new ThirdPartyInfo("ZXing", "https://github.com/zxing/zxing", "Apache 2.0")); - USED_LIBRARIES.add(new ThirdPartyInfo("ZXing Android Embedded", "https://github.com/journeyapps/zxing-android-embedded", "Apache 2.0")); - StringBuilder libs = new StringBuilder().append("
"); - for (ThirdPartyInfo entry : USED_LIBRARIES) { - libs.append("
").append(entry.name()).append(" (").append(entry.license()).append(")"); - } - - return libs.toString(); - } - - private String getUsedThirdPartyAssets() { - final List USED_ASSETS = new ArrayList<>(); - USED_ASSETS.add(new ThirdPartyInfo("Android icons", "https://fonts.google.com/icons?selected=Material+Icons", "Apache 2.0")); - - StringBuilder resources = new StringBuilder().append("
"); - for (ThirdPartyInfo entry : USED_ASSETS) { - resources.append("
").append(entry.name()).append(" (").append(entry.license()).append(")"); - } - - return resources.toString(); - } - - private String getContributorInfo() { - StringBuilder contributorInfo = new StringBuilder(); - contributorInfo.append(HtmlCompat.fromHtml(String.format(getString(R.string.app_contributors), getContributors()), HtmlCompat.FROM_HTML_MODE_COMPACT)); - contributorInfo.append("\n\n"); - contributorInfo.append(getString(R.string.app_copyright_old)); - contributorInfo.append("\n\n"); - contributorInfo.append(HtmlCompat.fromHtml(String.format(getString(R.string.app_libraries), getThirdPartyLibraries()), HtmlCompat.FROM_HTML_MODE_COMPACT)); - contributorInfo.append("\n\n"); - contributorInfo.append(HtmlCompat.fromHtml(String.format(getString(R.string.app_resources), getUsedThirdPartyAssets()), HtmlCompat.FROM_HTML_MODE_COMPACT)); - - return contributorInfo.toString(); - } } diff --git a/app/src/main/java/protect/card_locker/AboutContent.java b/app/src/main/java/protect/card_locker/AboutContent.java new file mode 100644 index 000000000..926418f8f --- /dev/null +++ b/app/src/main/java/protect/card_locker/AboutContent.java @@ -0,0 +1,112 @@ +package protect.card_locker; + +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.util.Log; + +import androidx.core.text.HtmlCompat; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + +public class AboutContent { + + public static final String TAG = "Catima"; + + public Context context; + + public AboutContent(Context context) { + this.context = context; + } + + public void destroy() { + this.context = null; + } + + public String getAppVersion() { + String version = "?"; + try { + PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); + version = pi.versionName; + } catch (PackageManager.NameNotFoundException e) { + Log.w(TAG, "Package name not found", e); + } + + return version; + } + + public int getCurrentYear() { + return Calendar.getInstance().get(Calendar.YEAR); + } + + public String getContributors() { + StringBuilder contributors = new StringBuilder().append("
"); + + BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().openRawResource(R.raw.contributors), StandardCharsets.UTF_8)); + + try { + while (true) { + String tmp = reader.readLine(); + + if (tmp == null || tmp.isEmpty()) { + reader.close(); + break; + } + + contributors.append("
"); + contributors.append(tmp); + } + } catch (IOException ignored) { + } + + return contributors.toString(); + } + + public String getThirdPartyLibraries() { + final List USED_LIBRARIES = new ArrayList<>(); + USED_LIBRARIES.add(new ThirdPartyInfo("Color Picker", "https://github.com/jaredrummler/ColorPicker", "Apache 2.0")); + USED_LIBRARIES.add(new ThirdPartyInfo("Commons CSV", "https://commons.apache.org/proper/commons-csv/", "Apache 2.0")); + USED_LIBRARIES.add(new ThirdPartyInfo("NumberPickerPreference", "https://github.com/invissvenska/NumberPickerPreference", "GNU LGPL 3.0")); + USED_LIBRARIES.add(new ThirdPartyInfo("uCrop", "https://github.com/Yalantis/uCrop", "Apache 2.0")); + USED_LIBRARIES.add(new ThirdPartyInfo("Zip4j", "https://github.com/srikanth-lingala/zip4j", "Apache 2.0")); + USED_LIBRARIES.add(new ThirdPartyInfo("ZXing", "https://github.com/zxing/zxing", "Apache 2.0")); + USED_LIBRARIES.add(new ThirdPartyInfo("ZXing Android Embedded", "https://github.com/journeyapps/zxing-android-embedded", "Apache 2.0")); + StringBuilder libs = new StringBuilder().append("
"); + for (ThirdPartyInfo entry : USED_LIBRARIES) { + libs.append("
").append(entry.name()).append(" (").append(entry.license()).append(")"); + } + + return libs.toString(); + } + + public String getUsedThirdPartyAssets() { + final List USED_ASSETS = new ArrayList<>(); + USED_ASSETS.add(new ThirdPartyInfo("Android icons", "https://fonts.google.com/icons?selected=Material+Icons", "Apache 2.0")); + + StringBuilder resources = new StringBuilder().append("
"); + for (ThirdPartyInfo entry : USED_ASSETS) { + resources.append("
").append(entry.name()).append(" (").append(entry.license()).append(")"); + } + + return resources.toString(); + } + + public String getContributorInfo() { + StringBuilder contributorInfo = new StringBuilder(); + contributorInfo.append(HtmlCompat.fromHtml(String.format(context.getString(R.string.app_contributors), getContributors()), HtmlCompat.FROM_HTML_MODE_COMPACT)); + contributorInfo.append("\n\n"); + contributorInfo.append(context.getString(R.string.app_copyright_old)); + contributorInfo.append("\n\n"); + contributorInfo.append(HtmlCompat.fromHtml(String.format(context.getString(R.string.app_libraries), getThirdPartyLibraries()), HtmlCompat.FROM_HTML_MODE_COMPACT)); + contributorInfo.append("\n\n"); + contributorInfo.append(HtmlCompat.fromHtml(String.format(context.getString(R.string.app_resources), getUsedThirdPartyAssets()), HtmlCompat.FROM_HTML_MODE_COMPACT)); + + return contributorInfo.toString(); + } +}