mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 08:40:03 +02:00
Create QR-Code for profile URL
This commit is contained in:
parent
9907717638
commit
86e8e639a3
7 changed files with 123 additions and 2 deletions
|
@ -190,7 +190,7 @@ dependencies {
|
||||||
implementation 'androidx.media:media:1.7.0'
|
implementation 'androidx.media:media:1.7.0'
|
||||||
implementation 'com.github.mancj:MaterialSearchBar:0.8.5'
|
implementation 'com.github.mancj:MaterialSearchBar:0.8.5'
|
||||||
|
|
||||||
|
implementation 'com.github.androidmads:QRGenerator:1.0.1'
|
||||||
|
|
||||||
implementation 'io.noties.markwon:core:4.6.2'
|
implementation 'io.noties.markwon:core:4.6.2'
|
||||||
implementation 'io.noties.markwon:ext-tables:4.6.2'
|
implementation 'io.noties.markwon:ext-tables:4.6.2'
|
||||||
|
|
|
@ -15,6 +15,10 @@ package app.fedilab.android.mastodon.activities;
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import static app.fedilab.android.mastodon.helper.LogoHelper.getMainLogo;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
|
@ -23,9 +27,13 @@ import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.drawable.Animatable;
|
import android.graphics.drawable.Animatable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
|
@ -39,6 +47,7 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.webkit.URLUtil;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
@ -62,6 +71,9 @@ import com.bumptech.glide.request.transition.Transition;
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -72,12 +84,15 @@ import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import androidmads.library.qrgenearator.QRGContents;
|
||||||
|
import androidmads.library.qrgenearator.QRGEncoder;
|
||||||
import app.fedilab.android.BaseMainActivity;
|
import app.fedilab.android.BaseMainActivity;
|
||||||
import app.fedilab.android.BuildConfig;
|
import app.fedilab.android.BuildConfig;
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.activities.MainActivity;
|
import app.fedilab.android.activities.MainActivity;
|
||||||
import app.fedilab.android.databinding.ActivityProfileBinding;
|
import app.fedilab.android.databinding.ActivityProfileBinding;
|
||||||
import app.fedilab.android.databinding.NotificationsRelatedAccountsBinding;
|
import app.fedilab.android.databinding.NotificationsRelatedAccountsBinding;
|
||||||
|
import app.fedilab.android.databinding.PopupQrcodeBinding;
|
||||||
import app.fedilab.android.databinding.TabProfileCustomViewBinding;
|
import app.fedilab.android.databinding.TabProfileCustomViewBinding;
|
||||||
import app.fedilab.android.mastodon.client.entities.api.Account;
|
import app.fedilab.android.mastodon.client.entities.api.Account;
|
||||||
import app.fedilab.android.mastodon.client.entities.api.Attachment;
|
import app.fedilab.android.mastodon.client.entities.api.Attachment;
|
||||||
|
@ -275,6 +290,51 @@ public class ProfileActivity extends BaseActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
binding.qrCodeGenerator.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
binding.qrCodeGenerator.setOnClickListener(v->{
|
||||||
|
QRGEncoder qrgEncoder = new QRGEncoder(account.url, null, QRGContents.Type.TEXT, 400);
|
||||||
|
Drawable logoDrawable = ContextCompat.getDrawable(ProfileActivity.this, R.drawable.fedilab_logo_bubbles);
|
||||||
|
if (logoDrawable != null) {
|
||||||
|
Bitmap bitmap = qrgEncoder.getBitmap();
|
||||||
|
MaterialAlertDialogBuilder alertadd = new MaterialAlertDialogBuilder(ProfileActivity.this);
|
||||||
|
PopupQrcodeBinding popupQrcodeBinding = PopupQrcodeBinding.inflate(getLayoutInflater());
|
||||||
|
popupQrcodeBinding.qrcodeImage.setImageBitmap(bitmap);
|
||||||
|
alertadd.setView(popupQrcodeBinding.getRoot());
|
||||||
|
alertadd.setNeutralButton(R.string.close, (dialog, which) -> dialog.dismiss());
|
||||||
|
alertadd.setPositiveButton(R.string.save, (dlg, which) -> {
|
||||||
|
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
|
||||||
|
File targeted_folder = new File(path, getString(R.string.app_name));
|
||||||
|
if (!targeted_folder.exists()) {
|
||||||
|
boolean created = targeted_folder.mkdir();
|
||||||
|
if (!created) {
|
||||||
|
Toasty.error(ProfileActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String fileName = URLUtil.guessFileName(account.url, null, null);
|
||||||
|
if (fileName.endsWith(".bin")) {
|
||||||
|
fileName = fileName.replace(".bin", ".png");
|
||||||
|
}
|
||||||
|
fileName = fileName.replaceAll("@","");
|
||||||
|
File backupFile = new File(targeted_folder.getAbsolutePath() + "/" + fileName);
|
||||||
|
try (FileOutputStream out = new FileOutputStream(backupFile)) {
|
||||||
|
final Intent intent = new Intent();
|
||||||
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
|
Uri uri = Uri.fromFile(backupFile);
|
||||||
|
intent.setDataAndType(uri, "image/jpeg");
|
||||||
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
|
||||||
|
Helper.notify_user(ProfileActivity.this, Helper.getCurrentAccount(ProfileActivity.this), intent, BitmapFactory.decodeResource(getResources(),
|
||||||
|
getMainLogo(ProfileActivity.this)), Helper.NotifType.STORE, getString(R.string.save_over), getString(R.string.download_from, fileName));
|
||||||
|
Toasty.success(ProfileActivity.this, getString(R.string.save_over), Toasty.LENGTH_LONG).show();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
alertadd.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
//Retrieve relationship with the connected account
|
//Retrieve relationship with the connected account
|
||||||
List<String> accountListToCheck = new ArrayList<>();
|
List<String> accountListToCheck = new ArrayList<>();
|
||||||
|
|
|
@ -219,6 +219,7 @@ public class Helper {
|
||||||
public static final String ARG_NOTIFICATION_TYPE = "ARG_NOTIFICATION_TYPE";
|
public static final String ARG_NOTIFICATION_TYPE = "ARG_NOTIFICATION_TYPE";
|
||||||
public static final String ARG_EXCLUDED_NOTIFICATION_TYPE = "ARG_EXCLUDED_NOTIFICATION_TYPE";
|
public static final String ARG_EXCLUDED_NOTIFICATION_TYPE = "ARG_EXCLUDED_NOTIFICATION_TYPE";
|
||||||
public static final String ARG_STATUS = "ARG_STATUS";
|
public static final String ARG_STATUS = "ARG_STATUS";
|
||||||
|
public static final String ARG_QR_CODE_URL = "ARG_QR_CODE_URL";
|
||||||
public static final String ARG_FOCUSED_STATUS_URI = "ARG_FOCUSED_STATUS_URI";
|
public static final String ARG_FOCUSED_STATUS_URI = "ARG_FOCUSED_STATUS_URI";
|
||||||
public static final String ARG_TIMELINE_REFRESH_ALL = "ARG_TIMELINE_REFRESH_ALL";
|
public static final String ARG_TIMELINE_REFRESH_ALL = "ARG_TIMELINE_REFRESH_ALL";
|
||||||
public static final String ARG_REFRESH_NOTFICATION = "ARG_REFRESH_NOTFICATION";
|
public static final String ARG_REFRESH_NOTFICATION = "ARG_REFRESH_NOTFICATION";
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:height="24dp" android:tint="?attr/colorControlNormal" android:viewportHeight="24"
|
||||||
|
android:viewportWidth="24" android:width="24dp">
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M3,11h8V3H3V11zM5,5h4v4H5V5z"/>
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M3,21h8v-8H3V21zM5,15h4v4H5V15z"/>
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M13,3v8h8V3H13zM19,9h-4V5h4V9z"/>
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M19,19h2v2h-2z"/>
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M13,13h2v2h-2z"/>
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M15,15h2v2h-2z"/>
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M13,17h2v2h-2z"/>
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M15,19h2v2h-2z"/>
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M17,17h2v2h-2z"/>
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M17,13h2v2h-2z"/>
|
||||||
|
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M19,15h2v2h-2z"/>
|
||||||
|
|
||||||
|
</vector>
|
|
@ -140,7 +140,22 @@
|
||||||
app:layout_constraintStart_toStartOf="@id/banner_container"
|
app:layout_constraintStart_toStartOf="@id/banner_container"
|
||||||
app:layout_constraintTop_toBottomOf="@id/avatar_container"
|
app:layout_constraintTop_toBottomOf="@id/avatar_container"
|
||||||
tools:text="@tools:sample/first_names" />
|
tools:text="@tools:sample/first_names" />
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/qr_code_generator"
|
||||||
|
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||||
|
android:layout_width="36dp"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:layout_marginTop="6dp"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
app:iconGravity="textStart"
|
||||||
|
app:iconPadding="0dp"
|
||||||
|
android:contentDescription="@string/qr_code_generator"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:icon="@drawable/baseline_qr_code_24"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/account_dn"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/avatar_container"
|
||||||
|
tools:visibility="visible" />
|
||||||
<androidx.appcompat.widget.LinearLayoutCompat
|
<androidx.appcompat.widget.LinearLayoutCompat
|
||||||
android:id="@+id/account_un_container"
|
android:id="@+id/account_un_container"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
17
app/src/main/res/layouts/mastodon/layout/popup_qrcode.xml
Normal file
17
app/src/main/res/layouts/mastodon/layout/popup_qrcode.xml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="12dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:contentDescription="@string/qr_code_generator"
|
||||||
|
android:id="@+id/qrcode_image"
|
||||||
|
tools:src="@tools:sample/backgrounds/scenic"
|
||||||
|
android:scaleType="centerInside"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -583,6 +583,7 @@
|
||||||
<string name="icons_color">Color of bottom icons in timelines</string>
|
<string name="icons_color">Color of bottom icons in timelines</string>
|
||||||
<string name="logo_of_the_instance">Logo of the instance</string>
|
<string name="logo_of_the_instance">Logo of the instance</string>
|
||||||
<string name="edit_profile">Edit profile</string>
|
<string name="edit_profile">Edit profile</string>
|
||||||
|
<string name="qr_code_generator">QR generator</string>
|
||||||
<string name="make_an_action">Make an action</string>
|
<string name="make_an_action">Make an action</string>
|
||||||
<string name="translation">Translation</string>
|
<string name="translation">Translation</string>
|
||||||
<string name="text_color_title">Text color</string>
|
<string name="text_color_title">Text color</string>
|
||||||
|
|
Loading…
Reference in a new issue