FairEmail/app/src/main/java/eu/faircode/email/FragmentAbout.java

151 lines
5.5 KiB
Java
Raw Normal View History

package eu.faircode.email;
/*
2018-08-14 05:53:24 +00:00
This file is part of FairEmail.
2018-08-14 05:53:24 +00:00
FairEmail 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.
2018-10-29 10:46:49 +00:00
FairEmail 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
2018-10-29 10:46:49 +00:00
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2024-01-01 07:50:49 +00:00
Copyright 2018-2024 by Marcel Bokhorst (M66B)
*/
2020-08-29 07:31:43 +00:00
import android.content.Context;
2021-03-24 11:26:42 +00:00
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
2020-08-18 15:25:19 +00:00
import android.graphics.Paint;
2019-04-19 13:16:40 +00:00
import android.net.Uri;
import android.os.Bundle;
2020-08-29 07:31:43 +00:00
import android.util.TypedValue;
import android.view.LayoutInflater;
2019-04-28 09:56:57 +00:00
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
2020-08-29 07:31:43 +00:00
import android.widget.LinearLayout;
import android.widget.TextView;
2018-08-08 06:55:47 +00:00
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
2020-08-29 07:31:43 +00:00
import androidx.core.widget.TextViewCompat;
2021-03-24 11:26:42 +00:00
import java.text.DateFormat;
2020-08-29 07:31:43 +00:00
import java.util.List;
2018-08-08 06:55:47 +00:00
2019-01-15 17:41:55 +00:00
public class FragmentAbout extends FragmentBase {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.menu_about);
2019-04-28 09:56:57 +00:00
setHasOptionsMenu(true);
2019-04-19 13:16:40 +00:00
2021-04-04 08:05:10 +00:00
final Context context = getContext();
View view = inflater.inflate(R.layout.fragment_about, container, false);
2019-04-19 13:16:40 +00:00
TextView tvVersion = view.findViewById(R.id.tvVersion);
2019-07-13 18:14:19 +00:00
TextView tvRelease = view.findViewById(R.id.tvRelease);
2022-01-30 10:46:08 +00:00
TextView tvDownloaded = view.findViewById(R.id.tvDownloaded);
2021-03-24 11:26:42 +00:00
TextView tvUpdated = view.findViewById(R.id.tvUpdated);
2020-08-18 15:25:19 +00:00
TextView tvGplV3 = view.findViewById(R.id.tvGplV3);
2020-08-29 07:31:43 +00:00
LinearLayout llContributors = view.findViewById(R.id.llContributors);
2021-09-18 09:49:01 +00:00
String version = BuildConfig.VERSION_NAME + BuildConfig.REVISION;
tvVersion.setText(getString(R.string.title_version, version));
2019-07-13 18:14:19 +00:00
tvRelease.setText(BuildConfig.RELEASE_NAME);
2023-11-03 15:39:44 +00:00
String type = Log.getReleaseType(context) + (BuildConfig.DEBUG ? " (Debug)" : "");
tvDownloaded.setText(getString(R.string.app_download, type));
2022-01-30 10:46:08 +00:00
2021-03-24 11:26:42 +00:00
long last = 0;
try {
2021-04-04 08:05:10 +00:00
PackageManager pm = context.getPackageManager();
2021-03-24 11:26:42 +00:00
PackageInfo pi = pm.getPackageInfo(BuildConfig.APPLICATION_ID, 0);
last = pi.lastUpdateTime;
} catch (Throwable ex) {
Log.e(ex);
}
2021-04-04 08:05:10 +00:00
DateFormat DF = Helper.getDateTimeInstance(context, DateFormat.SHORT, DateFormat.SHORT);
2021-03-24 11:26:42 +00:00
tvUpdated.setText(getString(R.string.app_updated, last == 0 ? "-" : DF.format(last)));
2022-01-30 10:46:08 +00:00
tvUpdated.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (BuildConfig.PLAY_STORE_RELEASE)
Helper.view(v.getContext(), Helper.getIntentRate(v.getContext()));
else
2021-09-22 18:28:22 +00:00
Helper.view(v.getContext(), Uri.parse(BuildConfig.CHANGELOG), false);
}
});
2020-08-18 15:25:19 +00:00
tvGplV3.setPaintFlags(tvGplV3.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
tvGplV3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
2021-03-19 14:18:49 +00:00
Helper.view(view.getContext(), Uri.parse(Helper.LICENSE_URI), true);
2020-08-18 15:25:19 +00:00
}
});
2020-08-29 07:31:43 +00:00
TypedValue style = new TypedValue();
2023-07-21 05:16:41 +00:00
context.getTheme().resolveAttribute(androidx.appcompat.R.style.TextAppearance_AppCompat_Small, style, true);
2020-08-29 07:31:43 +00:00
List<Contributor> contributors = Contributor.loadContributors(context);
for (Contributor contributor : contributors) {
TextView tv = new TextView(context);
TextViewCompat.setTextAppearance(tv, style.data);
tv.setText(contributor.toString());
llContributors.addView(tv);
}
2021-09-14 07:52:08 +00:00
FragmentDialogTheme.setBackground(context, view, false);
return view;
}
2019-04-28 09:56:57 +00:00
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_about, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
2021-02-05 10:15:02 +00:00
int itemId = item.getItemId();
if (itemId == R.id.menu_changelog) {
onMenuChangelog();
return true;
} else if (itemId == R.id.menu_attribution) {
onMenuAttribution();
return true;
2019-04-28 09:56:57 +00:00
}
2021-02-05 10:15:02 +00:00
return super.onOptionsItemSelected(item);
2019-04-28 09:56:57 +00:00
}
private void onMenuChangelog() {
2021-09-17 17:57:10 +00:00
Bundle args = new Bundle();
args.putString("name", "CHANGELOG.md");
FragmentDialogMarkdown fragment = new FragmentDialogMarkdown();
fragment.setArguments(args);
fragment.show(getParentFragmentManager(), "changelog");
2019-04-28 09:56:57 +00:00
}
2019-07-23 12:30:57 +00:00
private void onMenuAttribution() {
2019-07-23 14:59:12 +00:00
Bundle args = new Bundle();
args.putString("name", "ATTRIBUTION.md");
FragmentDialogMarkdown fragment = new FragmentDialogMarkdown();
fragment.setArguments(args);
2021-09-17 17:57:10 +00:00
fragment.show(getParentFragmentManager(), "attribution");
2019-07-23 12:30:57 +00:00
}
}