Add website button to license activity

Julien LepillerSun Jul 10 16:00:00+0200 2022

44d5437

Add website button to license activity

app/src/main/java/eu/lepiller/nani/LicenseActivity.java

1717
    ExpandableListAdapter adapter;
1818
1919
    public static class License {
20-
        private final String name, description, license;
20+
        private final String name, description, license, url;
2121
        private final List<License> subProjects;
2222
        private final Drawable drawable;
2323
24-
        License(String name, Drawable drawable, String description, String license, List<License> subProjects) {
24+
        License(String name, Drawable drawable, String url, String description, String license, List<License> subProjects) {
2525
            this.name = name;
2626
            this.drawable = drawable;
27+
            this.url = url;
2728
            this.description = description;
2829
            this.license = license;
2930
            this.subProjects = subProjects;

4950
        public Drawable getDrawable() {
5051
            return drawable;
5152
        }
53+
54+
        public String getUrl() {
55+
            return url;
56+
        }
5257
    }
5358
5459
    private static final List<License> licenseInformation = new ArrayList<>();

6065
6166
        licenseInformation.clear();
6267
        List<License> erdrgLicenses = new ArrayList<>();
63-
        erdrgLicenses.add(new License(getString(R.string.jmdict_title), null,
68+
        erdrgLicenses.add(new License(getString(R.string.jmdict_title), null, "http://www.edrdg.org/wiki/index.php/JMdict-EDICT_Dictionary_Project",
6469
                getString(R.string.jmdict_descr), getString(R.string.jmdict_license), null));
65-
        erdrgLicenses.add(new License(getString(R.string.radk_title), null,
70+
        erdrgLicenses.add(new License(getString(R.string.radk_title), null, "http://www.edrdg.org/krad/kradinf.html",
6671
                getString(R.string.radk_descr), getString(R.string.radk_license), null));
67-
        erdrgLicenses.add(new License(getString(R.string.kanjidic_title), null,
72+
        erdrgLicenses.add(new License(getString(R.string.kanjidic_title), null, "http://www.edrdg.org/wiki/index.php/KANJIDIC_Project",
6873
                getString(R.string.kanjidic_descr), getString(R.string.kanjidic_license), null));
6974
        licenseInformation.add(
70-
                new License(getString(R.string.erdrg_title), ResourcesCompat.getDrawable(getResources(), R.drawable.ic_nani_edrdg, getTheme()),
75+
                new License(getString(R.string.erdrg_title), ResourcesCompat.getDrawable(getResources(), R.drawable.ic_nani_edrdg, getTheme()), null,
7176
                        getString(R.string.erdrg_descr), "", erdrgLicenses));
7277
7378
        licenseInformation.add(
74-
                new License(getString(R.string.kanjivg_title), ResourcesCompat.getDrawable(getResources(), R.drawable.ic_kanjivg, getTheme()),
79+
                new License(getString(R.string.kanjivg_title), ResourcesCompat.getDrawable(getResources(), R.drawable.ic_kanjivg, getTheme()), "http://kanjivg.tagaini.net/",
7580
                        getString(R.string.kanjivg_descr), getString(R.string.kanjivg_license), null)
7681
        );
7782
        licenseInformation.add(
78-
                new License(getString(R.string.jibiki_title), ResourcesCompat.getDrawable(getResources(), R.drawable.ic_jibiki, getTheme()),
83+
                new License(getString(R.string.jibiki_title), ResourcesCompat.getDrawable(getResources(), R.drawable.ic_jibiki, getTheme()), "https://jibiki.fr",
7984
                        getString(R.string.jibiki_descr), getString(R.string.jibiki_license), null)
8085
        );
8186
        licenseInformation.add(
82-
                new License(getString(R.string.wadoku_title), ResourcesCompat.getDrawable(getResources(), R.drawable.wadoku, getTheme()),
87+
                new License(getString(R.string.wadoku_title), ResourcesCompat.getDrawable(getResources(), R.drawable.wadoku, getTheme()), "https://wadoku.de",
8388
                        getString(R.string.wadoku_descr), getString(R.string.wadoku_license), null)
8489
        );
8590
        licenseInformation.add(
86-
                new License(getString(R.string.tatoeba_title), ResourcesCompat.getDrawable(getResources(), R.drawable.ic_tatoeba, getTheme()),
91+
                new License(getString(R.string.tatoeba_title), ResourcesCompat.getDrawable(getResources(), R.drawable.ic_tatoeba, getTheme()), "https://tatoeba.org",
8792
                        getString(R.string.tatoeba_descr), getString(R.string.tatoeba_license), null)
8893
        );
8994

app/src/main/java/eu/lepiller/nani/LicenseAdapter.java

11
package eu.lepiller.nani;
22
33
import android.content.Context;
4+
import android.content.Intent;
45
import android.graphics.drawable.Drawable;
6+
import android.net.Uri;
57
import android.provider.ContactsContract;
68
import android.view.LayoutInflater;
79
import android.view.View;
810
import android.view.ViewGroup;
911
import android.widget.BaseExpandableListAdapter;
12+
import android.widget.Button;
1013
import android.widget.ImageView;
1114
import android.widget.TextView;
1215

8992
                view = layoutInflater.inflate(R.layout.layout_license, viewGroup, false);
9093
            }
9194
92-
            TextView nameView = (TextView) view.findViewById(R.id.name);
93-
            TextView descriptionView = (TextView) view.findViewById(R.id.description);
94-
            TextView licenseView = (TextView) view.findViewById(R.id.license);
95+
            TextView nameView = view.findViewById(R.id.name);
96+
            TextView descriptionView = view.findViewById(R.id.description);
97+
            TextView licenseView = view.findViewById(R.id.license);
98+
            Button projectButton = view.findViewById(R.id.website_button);
9599
96100
            descriptionView.setText(licenses.get(i).getDescription());
97101
            nameView.setVisibility(View.GONE);
98102
            licenseView.setVisibility(View.GONE);
103+
            projectButton.setVisibility(View.GONE);
99104
            return view;
100105
        } else {
101106
            boolean subproject = projects != null && projects.size() > 0;

107112
                view = layoutInflater.inflate(R.layout.layout_license, viewGroup, false);
108113
            }
109114
110-
            TextView nameView = (TextView) view.findViewById(R.id.name);
111-
            TextView descriptionView = (TextView) view.findViewById(R.id.description);
112-
            TextView licenseView = (TextView) view.findViewById(R.id.license);
115+
            TextView nameView = view.findViewById(R.id.name);
116+
            TextView descriptionView = view.findViewById(R.id.description);
117+
            TextView licenseView = view.findViewById(R.id.license);
118+
            Button projectButton = view.findViewById(R.id.website_button);
113119
114120
            nameView.setVisibility(subproject? View.VISIBLE: View.GONE);
121+
            projectButton.setVisibility(license.getUrl() == null? View.GONE: View.VISIBLE);
115122
            licenseView.setVisibility(View.VISIBLE);
116123
124+
            if(license.getUrl() != null)
125+
                projectButton.setOnClickListener(view1 -> {
126+
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(license.getUrl()));
127+
                    context.startActivity(browserIntent);
128+
                });
129+
117130
            nameView.setText(license.getName());
118131
            descriptionView.setText(license.getDescription());
119132
            licenseView.setText(license.getLicense());

app/src/main/res/layout/layout_license.xml

2525
        android:layout_height="wrap_content"
2626
        android:layout_marginTop="16dp"
2727
        app:lineHeight="22dp" />
28+
29+
    <LinearLayout
30+
        android:orientation="vertical"
31+
        android:layout_width="match_parent"
32+
        android:layout_height="wrap_content">
33+
        <Button
34+
            android:layout_width="wrap_content"
35+
            android:layout_height="wrap_content"
36+
            android:gravity="center"
37+
            android:layout_gravity="center"
38+
            android:text="@string/project_website"
39+
            android:id="@+id/website_button"
40+
            android:padding="8dp"
41+
            android:layout_marginTop="16dp"
42+
            android:background="@color/colorSubtitle"
43+
            android:textColor="@color/colorGrey" />
44+
    </LinearLayout>
2845
</LinearLayout>
2845=
2946=
\ No newline at end of file

app/src/main/res/values/strings.xml

141141
        &lt;http://www.gnu.org/licenses/gpl.html&gt;.
142142
        </string>
143143
    <string name="data_licenses">Data Licenses</string>
144-
    <string name="data_intro">Nani? uses data from third party distributed under different licenses.</string>
144+
    <string name="data_intro">Nani? uses data from third parties, distributed under different licenses. Here is the list of third-party data providers and their license.</string>
145+
    <string name="project_website">Visit Website</string>
145146
146147
    <string name="erdrg_title">Electronic Dictionary Research and Development Group</string>
147148
    <string name="erdrg_descr">The Electronic Dictionary Research and Development Group was