- fix sharing callback

- some more minor adjustments
This commit is contained in:
Dorian Zedler 2021-06-20 16:51:31 +02:00
parent 06e76bc287
commit 0b8c253564
Signed by: dorian
GPG key ID: 989DE36109AFA354
10 changed files with 120 additions and 53 deletions

View file

@ -89,4 +89,5 @@
</application>
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>

View file

@ -1,3 +1,3 @@
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="my_shared_files" path="share_example_x_files/" />
<files-path name="temporaryFiles" path="temporaryFiles/" />
</paths>

View file

@ -16,6 +16,7 @@ public:
AndroidShareUtils(QObject* parent = nullptr);
bool checkMimeTypeView(const QString &mimeType) override;
bool checkMimeTypeEdit(const QString &mimeType) override;
virtual QString getTemporaryFileLocationPath() override;
void shareText(const QString &text) override;
void sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) override;
void viewFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) override;

View file

@ -18,6 +18,9 @@
#include <QObject>
#include <QDebug>
#include <QStandardPaths>
#include <QDesktopServices>
#include <QUrl>
class PlatformShareUtils : public QObject
{
@ -35,6 +38,7 @@ public:
virtual ~PlatformShareUtils();
virtual bool checkMimeTypeView(const QString &mimeType);
virtual bool checkMimeTypeEdit(const QString &mimeType);
virtual QString getTemporaryFileLocationPath();
virtual void shareText(const QString &text);
virtual void sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId);
virtual void viewFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId);

View file

@ -46,6 +46,7 @@ public:
explicit ShareUtils(QObject *parent = 0);
Q_INVOKABLE bool checkMimeTypeView(const QString &mimeType);
Q_INVOKABLE bool checkMimeTypeEdit(const QString &mimeType);
Q_INVOKABLE QString getTemporaryFileLocationPath();
Q_INVOKABLE void shareText(const QString &text);
Q_INVOKABLE void sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId);
Q_INVOKABLE void viewFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId);

View file

@ -1,7 +1,8 @@
import QtQuick 2.0
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QZXing 3.1
import QtGraphicalEffects 1.0
Dialog {
id: control
@ -31,56 +32,83 @@ Dialog {
Component {
id: shareComponent
StackLayout {
id: stackLayout
currentIndex: 0
id: stackLayout
currentIndex: 0
RowLayout {
id: menuRow
Repeater {
id: buttonRepeater
property var buttons: [
["\uf0c1", "Link", serverConn.shareResultsAsUrl],
["\uf029", "QR-code", function() {
stackLayout.currentIndex = 1
}
],
["\uf1c1", "Poster", serverConn.shareResultsAsPoster],
]
model: buttons
delegate: Button {
flat: true
font.family: fa5solid.name
text: "<font size=\"+4\">" + modelData[0] + "</font><br><br> " + modelData[1] + " "
onClicked: buttonRepeater.buttons[index][2](_shareUrl, _compName)
RowLayout {
id: menuRow
Repeater {
id: buttonRepeater
property var buttons: [
["\uf0c1", "Link", serverConn.shareResultsAsUrl],
["\uf029", "QR-code", function() {
stackLayout.currentIndex = 1
}
}
}
],
["\uf1c1", "Poster", serverConn.shareResultsAsPoster],
]
model: buttons
Image {
id: qrCodeImage
property int size: stackLayout.currentIndex === 1 ? (app.landscape() ? app.height * 0.8 : app.width * 0.8):menuRow.height
Layout.preferredHeight: size
Layout.preferredWidth: size
sourceSize.width: size
sourceSize.height: size
fillMode: Image.PreserveAspectFit
source: "image://QZXing/encode/" + _shareUrl + "?border=true&correctionLevel=H"
Behavior on size {
NumberAnimation {
duration: 200
}
delegate: Button {
flat: true
font.family: fa5solid.name
text: "<font size=\"+4\">" + modelData[0] + "</font><br><br> " + modelData[1] + " "
onClicked: buttonRepeater.buttons[index][2](_shareUrl, _compName)
}
}
}
Image {
id: qrCodeImage
property int finalSize: app.landscape() ? app.height * 0.8 : app.width * 0.8
property int size: stackLayout.currentIndex === 1 ? finalSize:menuRow.height
Layout.preferredHeight: size
Layout.preferredWidth: size
sourceSize.width: finalSize
sourceSize.height: finalSize
fillMode: Image.PreserveAspectFit
source: "image://QZXing/encode/" + _shareUrl + "?border=true&correctionLevel=H"
RectangularGlow {
id: effect
anchors.fill: blurRockLogoBackgroundRect
glowRadius: 0
spread: 0
opacity: 0.8
color: "black"
cornerRadius: blurRockLogoBackgroundRect.radius
}
Rectangle {
id: blurRockLogoBackgroundRect
anchors.centerIn: parent
width: parent.width * 0.25
height: width
radius: height * 0.2
color: "white"
Image {
anchors.centerIn: parent
width: parent.width * 0.8
height: width
mipmap: true
source: "qrc:/icons/blueRockHold.png"
}
}
Behavior on size {
NumberAnimation {
duration: 200
}
}
}
}
}
function appear(shareUrl, compName) {

View file

@ -97,9 +97,26 @@ void BlueRockBackend::shareResultsAsUrl(QString url, QString compName) {
}
void BlueRockBackend::shareResultsAsPoster(QString url, QString compName) {
QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
QString path = this->_shareUtils->getTemporaryFileLocationPath(); //QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
if (!QDir(path).exists()) {
if (QDir("").mkpath(path)) {
qDebug() << "Created app data /files directory. " << path;
} else {
qWarning() << "Failed to create app data /files directory. " << path;
return;
}
}
path += "/" + compName + ".pdf";
QPdfWriter writer(path);
QFile file(path);
file.remove();
if(!file.open(QIODevice::ReadWrite)) {
qWarning("Could not open File for writing!!");
return;
}
QPdfWriter writer(&file);
writer.setPageSize(QPageSize(QPageSize::A4));
writer.setPageMargins(QMargins(0, 0, 0, 0));
writer.setResolution(600);
@ -115,9 +132,9 @@ void BlueRockBackend::shareResultsAsPoster(QString url, QString compName) {
painter.drawPixmap((writer.width() - size) / 2, size * 0.5, size, size, barcode);
painter.end();
file.close();
int requestId;
this->_shareUtils->sendFile(path, compName, "application/pdf", requestId);
this->_shareUtils->sendFile(path, compName, "application/pdf", 1);
}
// ------------------------

View file

@ -54,6 +54,10 @@ bool AndroidShareUtils::checkMimeTypeEdit(const QString &mimeType)
return verified;
}
QString AndroidShareUtils::getTemporaryFileLocationPath() {
return QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0) + "/temporaryFiles";
}
void AndroidShareUtils::shareText(const QString &text)
{
QAndroidJniObject jsText = QAndroidJniObject::fromString(text);
@ -296,7 +300,7 @@ extern "C" {
#endif
JNIEXPORT void JNICALL
Java_org_ekkescorner_examples_sharex_QShareActivity_setFileUrlReceived(JNIEnv *env,
Java_de_itsblue_blueROCK_MainActivity_setFileUrlReceived(JNIEnv *env,
jobject obj,
jstring url)
{
@ -308,7 +312,7 @@ Java_org_ekkescorner_examples_sharex_QShareActivity_setFileUrlReceived(JNIEnv *e
}
JNIEXPORT void JNICALL
Java_org_ekkescorner_examples_sharex_QShareActivity_setFileReceivedAndSaved(JNIEnv *env,
Java_de_itsblue_blueROCK_MainActivity_setFileReceivedAndSaved(JNIEnv *env,
jobject obj,
jstring url)
{
@ -320,7 +324,7 @@ Java_org_ekkescorner_examples_sharex_QShareActivity_setFileReceivedAndSaved(JNIE
}
JNIEXPORT bool JNICALL
Java_org_ekkescorner_examples_sharex_QShareActivity_checkFileExits(JNIEnv *env,
Java_de_itsblue_blueROCK_MainActivity_checkFileExits(JNIEnv *env,
jobject obj,
jstring url)
{
@ -332,7 +336,7 @@ Java_org_ekkescorner_examples_sharex_QShareActivity_checkFileExits(JNIEnv *env,
}
JNIEXPORT void JNICALL
Java_org_ekkescorner_examples_sharex_QShareActivity_fireActivityResult(JNIEnv *env,
Java_de_itsblue_blueROCK_MainActivity_fireActivityResult(JNIEnv *env,
jobject obj,
jint requestCode,
jint resultCode)

View file

@ -17,17 +17,23 @@ bool PlatformShareUtils::checkMimeTypeEdit(const QString &mimeType) {
qDebug() << "check edit for " << mimeType;
return true;
}
QString PlatformShareUtils::getTemporaryFileLocationPath() {
return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
}
void PlatformShareUtils::shareText(const QString &text) {
qDebug() << text;
}
void PlatformShareUtils::sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) {
qDebug() << filePath << " - " << title << "requestId " << requestId << " - " << mimeType << "altImpl? ";
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
}
void PlatformShareUtils::viewFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) {
qDebug() << filePath << " - " << title << " requestId: " << requestId << " - " << mimeType << "altImpl? ";
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
}
void PlatformShareUtils::editFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) {
qDebug() << filePath << " - " << title << " requestId: " << requestId << " - " << mimeType << "altImpl? ";
QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
}
void PlatformShareUtils::checkPendingIntents(const QString workingDirPath) {

View file

@ -54,6 +54,11 @@ bool ShareUtils::checkMimeTypeEdit(const QString &mimeType)
return mPlatformShareUtils->checkMimeTypeEdit(mimeType);
}
QString ShareUtils::getTemporaryFileLocationPath()
{
return mPlatformShareUtils->getTemporaryFileLocationPath();
}
void ShareUtils::shareText(const QString &text)
{
mPlatformShareUtils->shareText(text);