UntrackMe-app-android-redir.../app/src/main/java/app/fedilab/nitterizeme/AboutActivity.java

179 lines
8.4 KiB
Java
Raw Normal View History

2020-01-25 10:25:02 +01:00
package app.fedilab.nitterizeme;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of NitterizeMe
*
* 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.
*
* NitterizeMe 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 NitterizeMe; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
2020-02-18 17:37:53 +01:00
import android.text.Spannable;
2020-01-25 10:25:02 +01:00
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
import android.view.MenuItem;
2020-02-18 17:37:53 +01:00
import android.view.View;
2020-01-25 15:47:10 +01:00
import android.widget.Button;
2020-02-18 17:37:53 +01:00
import android.widget.ImageView;
import android.widget.LinearLayout;
2020-01-25 10:25:02 +01:00
import android.widget.TextView;
2020-02-18 17:37:53 +01:00
import androidx.appcompat.app.AlertDialog;
2020-01-25 10:25:02 +01:00
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
public class AboutActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
TextView about_version = findViewById(R.id.about_version);
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;
about_version.setText(getResources().getString(R.string.about_vesrion, version));
2020-02-18 12:25:20 +01:00
} catch (PackageManager.NameNotFoundException ignored) {
}
2020-01-25 10:25:02 +01:00
setTitle(R.string.about_the_app);
2020-02-18 12:25:20 +01:00
if (getSupportActionBar() != null) {
2020-01-25 10:25:02 +01:00
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
//Developer click for Mastodon account
TextView developer_mastodon = findViewById(R.id.developer_mastodon);
SpannableString content = new SpannableString(developer_mastodon.getText().toString());
2020-02-18 12:25:20 +01:00
content.setSpan(new ForegroundColorSpan(ContextCompat.getColor(AboutActivity.this, R.color.colorAccent)), 0, content.length(), 0);
2020-01-25 10:25:02 +01:00
developer_mastodon.setText(content);
developer_mastodon.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://toot.fedilab.app/@fedilab"));
startActivity(browserIntent);
});
//Developer Github
TextView github = findViewById(R.id.github);
content = new SpannableString(github.getText().toString());
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
github.setText(content);
github.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/stom79"));
startActivity(browserIntent);
});
//Developer Framagit
TextView framagit = findViewById(R.id.framagit);
content = new SpannableString(framagit.getText().toString());
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
framagit.setText(content);
framagit.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://framagit.org/tom79"));
startActivity(browserIntent);
});
//Developer Codeberg
TextView codeberg = findViewById(R.id.codeberg);
content = new SpannableString(codeberg.getText().toString());
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
codeberg.setText(content);
codeberg.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://codeberg.org/tom79"));
startActivity(browserIntent);
});
//Developer donation
2020-02-17 17:32:28 +01:00
Button donatePaypal = findViewById(R.id.donate_paypal);
donatePaypal.setOnClickListener(v -> {
2020-02-18 17:37:53 +01:00
if (BuildConfig.DONATIONS) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.paypal.me/Mastalab"));
startActivity(browserIntent);
}else{
AlertDialog.Builder builder = new AlertDialog.Builder(AboutActivity.this);
builder.setTitle(R.string.donation_unavailable);
View view = getLayoutInflater().inflate(R.layout.popup_cannot_donate, new LinearLayout(getApplicationContext()), false);
ImageView get_fdroid = view.findViewById(R.id.get_fdroid);
get_fdroid.setOnClickListener( v1->{
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://f-droid.org/packages/app.fedilab.nitterizeme/"));
startActivity(browserIntent);
});
builder.setView(view);
builder.setPositiveButton(R.string.close, (dialog, id) -> dialog.dismiss());
TextView textView = view.findViewById(R.id.text);
setColor(textView,getString(R.string.donation_unavailable_title,"PayPal"), "PayPal", ContextCompat.getColor(AboutActivity.this, R.color.colorAccent));
builder.show();
}
2020-01-25 10:25:02 +01:00
});
2020-02-17 17:32:28 +01:00
Button donateLiberapay = findViewById(R.id.donate_liberapay);
donateLiberapay.setOnClickListener(v -> {
2020-02-18 17:37:53 +01:00
if (BuildConfig.DONATIONS) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://liberapay.com/tom79/donate"));
startActivity(browserIntent);
}else{
AlertDialog.Builder builder = new AlertDialog.Builder(AboutActivity.this);
builder.setTitle(R.string.donation_unavailable);
View view = getLayoutInflater().inflate(R.layout.popup_cannot_donate, new LinearLayout(getApplicationContext()), false);
ImageView get_fdroid = view.findViewById(R.id.get_fdroid);
get_fdroid.setOnClickListener( v1->{
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://f-droid.org/packages/app.fedilab.nitterizeme/"));
startActivity(browserIntent);
});
builder.setView(view);
builder.setPositiveButton(R.string.close, (dialog, id) -> dialog.dismiss());
TextView textView = view.findViewById(R.id.text);
setColor(textView,getString(R.string.donation_unavailable_title,"Liberapay"), "Liberapay", ContextCompat.getColor(AboutActivity.this, R.color.colorAccent));
builder.show();
}
2020-02-17 17:32:28 +01:00
});
2020-01-25 10:25:02 +01:00
2020-02-17 17:59:06 +01:00
Button how_to = findViewById(R.id.how_to);
how_to.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://fedilab.app/wiki/nitterizeme/"));
startActivity(browserIntent);
});
2020-01-25 10:25:02 +01:00
TextView license = findViewById(R.id.license);
content = new SpannableString(license.getText().toString());
2020-02-18 12:25:20 +01:00
content.setSpan(new ForegroundColorSpan(ContextCompat.getColor(AboutActivity.this, R.color.colorAccent)), 0, content.length(), 0);
2020-01-25 10:25:02 +01:00
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
license.setText(content);
license.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.gnu.org/licenses/quick-guide-gplv3.fr.html"));
startActivity(browserIntent);
});
}
2020-02-17 17:59:06 +01:00
2020-01-25 10:25:02 +01:00
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
2020-02-18 17:37:53 +01:00
private void setColor(TextView view, String fulltext, String subtext, int color) {
view.setText(fulltext, TextView.BufferType.SPANNABLE);
Spannable str = (Spannable) view.getText();
int i = fulltext.indexOf(subtext);
str.setSpan(new ForegroundColorSpan(color), i, i + subtext.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
2020-01-25 10:25:02 +01:00
}