From c93e28cdc7dccad5b2dc466c5fd591c8bba630fa Mon Sep 17 00:00:00 2001 From: Gregor Santner Date: Sat, 27 Aug 2016 16:40:16 +0200 Subject: [PATCH] Load license, contributors, maintainers and 3party libs from ressources --- CONTRIBUTORS.md | 8 +-- LICENSE.md | 1 + app/build.gradle | 19 ++++-- .../activity/AboutActivity.java | 64 +++++++++++++++++-- .../dfa/diaspora_android/ui/HtmlTextView.java | 9 +++ .../dfa/diaspora_android/util/Helpers.java | 33 ++++++++++ app/src/main/res/layout/fragment_license.xml | 3 +- app/src/main/res/raw/license_third_party.tpl | 11 ++++ app/src/main/res/raw/maintainers.tpl | 5 ++ app/src/main/res/values/strings.xml | 39 ++--------- 10 files changed, 142 insertions(+), 50 deletions(-) create mode 100644 app/src/main/res/raw/license_third_party.tpl create mode 100644 app/src/main/res/raw/maintainers.tpl diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 29187ae8..f8403625 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -3,9 +3,9 @@ 02l>> If you helped by translating the app, please send a message on crowdin 03l>> 04l>> Schemes: -05l>> Firstname Lastname (Link) -06l>> Firstname Lastname (E-Mail) -07l>> Username (Link) -08l>> Username (E-Mail) +05l>> Firstname Lastname (Link): Text +06l>> Firstname Lastname (E-Mail): Text +07l>> Username (Link): Text +08l>> Username (E-Mail): Text ## 99l CONTRIBUTORS Abhijith Balan (abhijithb21@openmailbox.org): Malayalam translation diff --git a/LICENSE.md b/LICENSE.md index 7dce67d7..0b680493 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -15,4 +15,5 @@ along with this program. If not, see http://www.gnu.org/licenses/. # Splashscreen-Images + The splashscreen images can be found on [flickr](https://www.flickr.com/photos/129581906@N06/sets/72157651933980136/with/16594947123/). diff --git a/app/build.gradle b/app/build.gradle index e99874b3..6238cb91 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,14 +53,25 @@ dependencies { task copyRepoFiles(type: Copy) { - String[] copyFiles = ["README.md", "CONTRIBUTORS.md", "LICENSE.md", "CHANGELOG.md"] + String[] copyFiles = ["README.md", "LICENSE.md", "CHANGELOG.md"] from rootProject.files(copyFiles) into 'src/main/res/raw' rename { String fileName -> fileName.replace(fileName, fileName.toLowerCase()) } - filter { line -> (line.toString().matches("..l>>.*") || line.toString().startsWith("## 99l CONTRIBUTORS")) \ - ? null : line.toString().trim() + + // Filter Contributors file + from(rootProject.file("CONTRIBUTORS.md")) { + into '.' // Target already changed to 'src/main/res/raw' + rename { String fileName -> + fileName.replace(fileName, fileName.toLowerCase()) + } + filter { line -> + (line.toString().matches("..l>>.*") || line.toString().startsWith("## 99l CONTRIBUTORS")) ? null : line.toString().trim().replaceAll(" \\(.*\\)", "") + } } + } -tasks.copyRepoFiles.execute() \ No newline at end of file +tasks + . + copyRepoFiles.execute() \ No newline at end of file diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java index 94c2c713..6bf16f76 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/AboutActivity.java @@ -41,6 +41,11 @@ import android.widget.TextView; import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.data.AppSettings; +import com.github.dfa.diaspora_android.ui.HtmlTextView; +import com.github.dfa.diaspora_android.util.Helpers; + +import butterknife.BindView; +import butterknife.ButterKnife; /** * Activity that holds some fragments that show information about the app in a tab layout @@ -79,7 +84,6 @@ public class AboutActivity extends AppCompatActivity { TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); - } /** @@ -96,10 +100,10 @@ public class AboutActivity extends AppCompatActivity { View rootView = inflater.inflate(R.layout.fragment_about, container, false); TextView appVersion = (TextView) rootView.findViewById(R.id.fragment_about__app_version); - if(isAdded()) { + if (isAdded()) { try { PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); - appVersion.setText(getString(R.string.fragment_debug__app_version, pInfo.versionName+ " ("+pInfo.versionCode+")")); + appVersion.setText(getString(R.string.fragment_debug__app_version, pInfo.versionName + " (" + pInfo.versionCode + ")")); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); @@ -113,16 +117,62 @@ public class AboutActivity extends AppCompatActivity { * Fragment that shows information about the license of the app and used 3rd party libraries */ public static class LicenseFragment extends Fragment { + @BindView(R.id.fragment_license__licensetext) + HtmlTextView textLicenseBox; + + @BindView(R.id.fragment_license__3rdparty) + HtmlTextView textLicense3partyBox; + public LicenseFragment() { } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_license, container, false); + ButterKnife.bind(this, rootView); + final Context context = rootView.getContext(); + accentColor = Helpers.hexColorFromRessourceColor(context, R.color.colorAccent); + + textLicenseBox.setTextFormatted(getString(R.string.fragment_license__license_content, + getMaintainersHtml(context), + getContributorsHtml(context), + getLicenseHtml(context) + )); + + textLicense3partyBox.setTextFormatted( + getLicense3dPartyHtml(context) + ); return rootView; } + + private String accentColor; + + public String getContributorsHtml(Context context) { + String text = Helpers.readTextfileFromRawRessource(context, R.raw.contributors, + "* ", "
"); + return text; + } + + public String getMaintainersHtml(Context context) { + String text = Helpers.readTextfileFromRawRessource(context, R.raw.maintainers, "", "
"); + text = text + .replace("NEWENTRY", "* ") + .replace("SUBTABBY", "  "); + return text; + } + + public String getLicenseHtml(Context context) { + String text = Helpers.readTextfileFromRawRessource(context, R.raw.license, + "", "").replace("\n\n", "

"); + return text; + } + + public String getLicense3dPartyHtml(Context context) { + String text = Helpers.readTextfileFromRawRessource(context, R.raw.license_third_party, "", "
"); + text = text.replace("NEWENTRY", "* "); + return text; + } } /** @@ -141,13 +191,13 @@ public class AboutActivity extends AppCompatActivity { TextView appVersion = (TextView) rootView.findViewById(R.id.fragment_debug__app_version); TextView podDomain = (TextView) rootView.findViewById(R.id.fragment_debug__pod_domain); - if(isAdded()) { + if (isAdded()) { try { PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); AppSettings settings = ((App) getActivity().getApplication()).getSettings(); packageName.setText(pInfo.packageName); - appVersion.setText(getString(R.string.fragment_debug__app_version, pInfo.versionName+ " ("+pInfo.versionCode+")")); + appVersion.setText(getString(R.string.fragment_debug__app_version, pInfo.versionName + " (" + pInfo.versionCode + ")")); podDomain.setText(getString(R.string.fragment_debug__pod_domain, settings.getPodDomain())); } catch (PackageManager.NameNotFoundException e) { diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/HtmlTextView.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/HtmlTextView.java index 1fe23ef4..444088a6 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/HtmlTextView.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/HtmlTextView.java @@ -65,6 +65,15 @@ public class HtmlTextView extends TextView { * Linkify, format markdown and escape the displayed text. */ private void init(){ + formatHtmlAndCustomTags(); + } + + public void setTextFormatted(String text){ + setText(text); + formatHtmlAndCustomTags(); + } + + private void formatHtmlAndCustomTags(){ setText(new SpannableString(Html.fromHtml(getText().toString()))); Linkify.TransformFilter filter = new Linkify.TransformFilter() { public final String transformUrl(final Matcher match, String url) { diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java index f424eda3..8a5988c9 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java @@ -26,8 +26,10 @@ import android.os.Environment; import com.github.dfa.diaspora_android.R; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; @@ -64,4 +66,35 @@ public class Helpers { storageDir /* directory */ ); } + + public static String readTextfileFromRawRessource(Context context, int rawRessourceId, String linePrefix, String linePostfix) { + StringBuilder sb = new StringBuilder(); + String line = ""; + BufferedReader br = null; + linePrefix = linePrefix == null ? "" : linePrefix; + linePostfix = linePostfix == null ? "" : linePostfix; + + try { + br = new BufferedReader(new InputStreamReader(context.getResources().openRawResource(rawRessourceId))); + while ((line = br.readLine()) != null) { + sb.append(linePrefix); + sb.append(line); + sb.append(linePostfix); + sb.append("\n"); + } + } catch (Exception ignored) { + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ignored) { + } + } + } + return sb.toString(); + } + + public static String hexColorFromRessourceColor(Context context, int idColor){ + return "#" + Integer.toHexString(context.getResources().getColor(idColor) & 0x00ffffff); + } } diff --git a/app/src/main/res/layout/fragment_license.xml b/app/src/main/res/layout/fragment_license.xml index ae3956a8..12b319c0 100644 --- a/app/src/main/res/layout/fragment_license.xml +++ b/app/src/main/res/layout/fragment_license.xml @@ -25,6 +25,7 @@ @@ -39,7 +40,7 @@ diff --git a/app/src/main/res/raw/license_third_party.tpl b/app/src/main/res/raw/license_third_party.tpl new file mode 100644 index 00000000..6aadb125 --- /dev/null +++ b/app/src/main/res/raw/license_third_party.tpl @@ -0,0 +1,11 @@ +NEWENTRY NetCipher +https://github.com/guardianproject/NetCipher + +NEWENTRY ButterKnife +https://jakewharton.github.io/butterknife + +NEWENTRY Android Support Library +https://developer.android.com/topic/libraries/support-library/index.html + +NEWENTRY Android Design Library +https://android-developers.blogspot.de/2015/05/android-design-support-library.html diff --git a/app/src/main/res/raw/maintainers.tpl b/app/src/main/res/raw/maintainers.tpl new file mode 100644 index 00000000..e08d72c6 --- /dev/null +++ b/app/src/main/res/raw/maintainers.tpl @@ -0,0 +1,5 @@ +NEWENTRY Gregor Santner (gsantner) +SUBTABBY https://gsantner.github.io + +NEWENTRY Paul Schaub (vanitasvitae) +SUBTABBY https://github.com/vanitasvitaes diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fa5e7187..74b47d4d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -107,30 +107,11 @@ Copyright © 2015–2016 - <b>Maintainers:</b><br> - - • gsantner<br> - https://gsantner.github.io<br> - • Paul Schaub (vanitasvitae)<br> - https://github.com/vanitasvitae<br> <br> - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see<br> - http://www.gnu.org/licenses.<br> <br> - - <i>The splashscreen images can be found on flickr: <br> - https://www.flickr.com/photos/129581906@N06/sets/72157651933980136/with/16594947123 <br> - They were published by \"Lydia\" and are licensed under cc by-nc-sa.</i> + + <h2>Maintainers:</h2> %1$s + <h2>Contributors:</h2> %2$s + <h2>License:</h2> %3$s + About License Debugging @@ -157,15 +138,5 @@ Also feel free to tell your friends about #DiasporaForAndroid! Auch gibt es niemanden, der den Schmerz an sich liebt, sucht oder wünscht, nur, weil er Schmerz ist, es sei denn, es kommt zu zufälligen Umständen, in denen Mühen und Schmerz ihm große Freude bereiten können. Um ein triviales Beispiel zu nehmen, wer von uns unterzieht sich je anstrengender körperlicher Betätigung, außer um Vorteile daraus zu ziehen? Aber wer hat irgend ein Recht, einen Menschen zu tadeln, der die Entscheidung trifft, eine Freude zu genießen, die keine unangenehmen Folgen hat, oder einen, der Schmerz vermeidet, welcher keine daraus resultierende Freude nach sich zieht? Auch gibt es niemanden, der den Schmerz an sich liebt, sucht oder wünscht, nur, weil er Schmerz ist, es sei denn, es kommt zu zufälligen Umständen, in denen Mühen und Schmerz ihm große Freude bereiten können. Um ein triviales Beispiel zu nehmen, wer von uns unterzieht sich je anstrengender körperlicher Betätigung, außer um Vorteile daraus zu ziehen? Aber wer hat irgend ein Recht, einen Menschen zu tadeln, der die Entscheidung trifft, eine Freude zu genießen, die keine unangenehmen Folgen hat, oder einen, der Schmerz vermeidet, welcher keine daraus resultierende Freude nach sich zieht? Used 3rd Party Libraries - - •Android Support Library:<br> - https://developer.android.com/topic/libraries/support-library/index.html <br> - •Anndroid Design Library:<br> - https://android-developers.blogspot.de/2015/05/android-design-support-library.html <br> - •NetCipher:<br> - https://github.com/guardianproject/NetCipher <br> - •ButterKnife:<br> - https://jakewharton.github.io/butterknife/ <br> -