Fix #1008 -Allow to copy app version from the about page

This commit is contained in:
Thomas 2023-12-19 15:56:26 +01:00
parent 4ce92e67b1
commit b6cbd8ea74
3 changed files with 46 additions and 7 deletions

View File

@ -15,12 +15,16 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Toast;
import androidx.core.app.ActivityOptionsCompat; import androidx.core.app.ActivityOptionsCompat;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
@ -40,6 +44,7 @@ import app.fedilab.android.mastodon.helper.CrossActionHelper;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.helper.MastodonHelper;
import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM; import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM;
import es.dmoral.toasty.Toasty;
public class AboutActivity extends BaseBarActivity { public class AboutActivity extends BaseBarActivity {
@ -58,10 +63,10 @@ public class AboutActivity extends BaseBarActivity {
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
String version = "";
try { try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName; version = pInfo.versionName;
binding.aboutVersion.setText(getResources().getString(R.string.about_vesrion, version)); binding.aboutVersion.setText(getResources().getString(R.string.about_vesrion, version));
} catch (PackageManager.NameNotFoundException ignored) { } catch (PackageManager.NameNotFoundException ignored) {
} }
@ -77,6 +82,20 @@ public class AboutActivity extends BaseBarActivity {
} }
binding.aboutSupportPaypal.setOnClickListener(v -> Helper.openBrowser(AboutActivity.this, "https://www.paypal.me/Mastalab")); binding.aboutSupportPaypal.setOnClickListener(v -> Helper.openBrowser(AboutActivity.this, "https://www.paypal.me/Mastalab"));
String finalVersion = version;
binding.aboutVersionCopy.setOnClickListener(v->{
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
String content = "Fedilab v" + finalVersion + " for " + (BuildConfig.DONATIONS?"FDroid":"Google");
ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content);
if (clipboard != null) {
clipboard.setPrimaryClip(clip);
Toasty.info(AboutActivity.this, getString(R.string.clipboard_version), Toast.LENGTH_LONG).show();
}
});
if (BuildConfig.DONATIONS) { if (BuildConfig.DONATIONS) {
binding.aboutSupportPaypal.setVisibility(View.VISIBLE); binding.aboutSupportPaypal.setVisibility(View.VISIBLE);
} else { } else {

View File

@ -35,14 +35,32 @@
android:text="@string/app_name" android:text="@string/app_name"
android:textSize="20sp" /> android:textSize="20sp" />
<!-- About version --> <!-- About version -->
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/about_version"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/about_version"
tools:text="x.y.z"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:textSize="16sp" /> android:textSize="16sp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/about_version_copy"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="36dp"
android:layout_height="36dp"
app:iconGravity="textStart"
app:iconPadding="0dp"
android:layout_marginStart="10dp"
android:contentDescription="@string/copy_version"
app:icon="@drawable/ic_copy_link"/>
</androidx.appcompat.widget.LinearLayoutCompat>
<!-- About developer --> <!-- About developer -->
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView

View File

@ -27,6 +27,7 @@
<string name="add_account">Add an account</string> <string name="add_account">Add an account</string>
<string name="clipboard">The content of the message has been copied to the clipboard</string> <string name="clipboard">The content of the message has been copied to the clipboard</string>
<string name="clipboard_url">The URL of the message has been copied to the clipboard</string> <string name="clipboard_url">The URL of the message has been copied to the clipboard</string>
<string name="clipboard_version">Information have been copied to the clipboard</string>
<string name="camera">Camera</string> <string name="camera">Camera</string>
<string name="delete_all">Delete all</string> <string name="delete_all">Delete all</string>
<string name="schedule">Schedule</string> <string name="schedule">Schedule</string>
@ -407,6 +408,7 @@
<string name="action_logout_account">Logout account</string> <string name="action_logout_account">Logout account</string>
<string name="all">All</string> <string name="all">All</string>
<string name="copy_link">Copy link</string> <string name="copy_link">Copy link</string>
<string name="copy_version">Copy information</string>
<string name="calls_blocked">http calls blocked by the application</string> <string name="calls_blocked">http calls blocked by the application</string>
<string name="list_of_blocked_domains">List of blocked calls</string> <string name="list_of_blocked_domains">List of blocked calls</string>
<string name="submit">Submit</string> <string name="submit">Submit</string>