Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ps484 #895

Merged
merged 34 commits into from
Sep 10, 2022
Merged

ps484 #895

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f18fc51
switched to new repo
Amean Aug 26, 2022
2ae1a68
finish switching to new repo
Amean Aug 26, 2022
68a3d45
added package call to provider
Amean Aug 29, 2022
e8f88bc
added package to service
Amean Aug 29, 2022
bcf3670
added service to manifest
Amean Aug 29, 2022
dcbd6f1
added pigeon dependency
Amean Aug 29, 2022
cf17e57
added message file for flutter android communication interface
Amean Aug 30, 2022
3544054
added message class ad abstract class with method declaration to message
Amean Aug 30, 2022
2642403
changed nft image type to String and deleted getCollections parameter
Amean Aug 30, 2022
1887930
placed pigeons dep in the dev dependencies
Amean Aug 30, 2022
2e2ea0c
autogenerated pigeon files
Amean Aug 30, 2022
b28477e
added collections api call to service
Amean Aug 30, 2022
eedd3f7
enabled async on message response and updated class name
Amean Aug 30, 2022
3f9aad2
updated getCollections call to use correct type
Amean Aug 30, 2022
bdf09dc
added getCollections implementation
Amean Aug 30, 2022
1a9699e
regenerated files for async messages
Amean Aug 30, 2022
cb83bec
removed home widget usage
Amean Aug 30, 2022
177a44e
added missing appwidget provider and intent imports
Amean Aug 31, 2022
6a816a1
added empty view
Amean Sep 1, 2022
5bd6975
added missing method implementations, passed in binary message to col…
Amean Sep 1, 2022
70cb9aa
fixed imports as well as layout and id calls
Amean Sep 1, 2022
1f01c3f
Merge branch 'main' into ps484
kjawadDeveloper2 Sep 2, 2022
42354c4
added flutter engine that produces binary message
Amean Sep 7, 2022
7e765a2
added image to test
Amean Sep 7, 2022
9665ac8
set jvm to 11
Amean Sep 7, 2022
0464ea4
Merge branch 'ps484' of https://github.com/Pylons-tech/pylons into ps484
Amean Sep 7, 2022
b1ba820
Merge branch 'main' of https://github.com/Pylons-tech/pylons into ps484
Amean Sep 7, 2022
6e6f989
removed unused home_widget dependency
Amean Sep 7, 2022
d0a3976
removed unused home widget import
Amean Sep 7, 2022
d1a07cc
added end of line to files
Amean Sep 7, 2022
ea547af
reorganized collectionsApi call
Amean Sep 7, 2022
d22380a
removed dead code
Amean Sep 7, 2022
16186d8
Merge branch 'main' into ps484
faddat Sep 8, 2022
4331ef9
Merge branch 'main' into ps484
faddat Sep 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions wallet/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

<receiver android:name="tech.pylons.flutter_wallet.PylonsWidgetProvider"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/pylons_widget_provider_info" />
</receiver>

<service android:name="tech.pylons.flutter_wallet.PylonsWidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS"
android:exported="false" />


<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="pylons_channel" />
Expand Down
118 changes: 118 additions & 0 deletions wallet/android/app/src/main/java/tech/pylons/wallet/Pigeon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Autogenerated from Pigeon (v3.2.6), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package tech.pylons.wallet;

import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.plugin.common.BasicMessageChannel;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MessageCodec;
import io.flutter.plugin.common.StandardMessageCodec;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

/** Generated class from Pigeon. */
@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"})
public class Pigeon {

/** Generated class from Pigeon that represents data sent in messages. */
public static class NFTMessage {
private @NonNull String imageUrl;
public @NonNull String getImageUrl() { return imageUrl; }
public void setImageUrl(@NonNull String setterArg) {
if (setterArg == null) {
throw new IllegalStateException("Nonnull field \"imageUrl\" is null.");
}
this.imageUrl = setterArg;
}

/** Constructor is private to enforce null safety; use Builder. */
private NFTMessage() {}
public static final class Builder {
private @Nullable String imageUrl;
public @NonNull Builder setImageUrl(@NonNull String setterArg) {
this.imageUrl = setterArg;
return this;
}
public @NonNull NFTMessage build() {
NFTMessage pigeonReturn = new NFTMessage();
pigeonReturn.setImageUrl(imageUrl);
return pigeonReturn;
}
}
@NonNull Map<String, Object> toMap() {
Map<String, Object> toMapResult = new HashMap<>();
toMapResult.put("imageUrl", imageUrl);
return toMapResult;
}
static @NonNull NFTMessage fromMap(@NonNull Map<String, Object> map) {
NFTMessage pigeonResult = new NFTMessage();
Object imageUrl = map.get("imageUrl");
pigeonResult.setImageUrl((String)imageUrl);
return pigeonResult;
}
}
private static class CollectionsApiCodec extends StandardMessageCodec {
public static final CollectionsApiCodec INSTANCE = new CollectionsApiCodec();
private CollectionsApiCodec() {}
@Override
protected Object readValueOfType(byte type, ByteBuffer buffer) {
switch (type) {
case (byte)128:
return NFTMessage.fromMap((Map<String, Object>) readValue(buffer));

default:
return super.readValueOfType(type, buffer);

}
}
@Override
protected void writeValue(ByteArrayOutputStream stream, Object value) {
if (value instanceof NFTMessage) {
stream.write(128);
writeValue(stream, ((NFTMessage) value).toMap());
} else
{
super.writeValue(stream, value);
}
}
}

/** Generated class from Pigeon that represents Flutter messages that can be called from Java.*/
public static class CollectionsApi {
private final BinaryMessenger binaryMessenger;
public CollectionsApi(BinaryMessenger argBinaryMessenger){
this.binaryMessenger = argBinaryMessenger;
}
public interface Reply<T> {
void reply(T reply);
}
static MessageCodec<Object> getCodec() {
return CollectionsApiCodec.INSTANCE;
}

public void getCollection(Reply<List<NFTMessage>> callback) {
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CollectionsApi.getCollection", getCodec());
channel.send(null, channelReply -> {
@SuppressWarnings("ConstantConditions")
List<NFTMessage> output = (List<NFTMessage>)channelReply;
callback.reply(output);
});
}
}
private static Map<String, Object> wrapError(Throwable exception) {
Map<String, Object> errorMap = new HashMap<>();
errorMap.put("message", exception.toString());
errorMap.put("code", exception.getClass().getSimpleName());
errorMap.put("details", "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception));
return errorMap;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
package tech.pylons.flutter_wallet

import io.flutter.embedding.android.FlutterActivity
import tech.pylons.wallet.Pigeon
import io.flutter.embedding.engine.FlutterEngine

class MainActivity: FlutterActivity() {
lateinit var collectionsApi: Pigeon.CollectionsApi

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)

collectionsApi = Pigeon.CollectionsApi(flutterEngine.dartExecutor.binaryMessenger)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package tech.pylons.flutter_wallet

import android.appwidget.AppWidgetManager
import android.content.Context
import android.net.Uri
import android.widget.RemoteViews
import android.content.Intent
import android.appwidget.AppWidgetProvider
import tech.pylons.wallet.R


class PylonsWidgetProvider : AppWidgetProvider() {

override fun onUpdate(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetIds: IntArray
) {
appWidgetIds.forEach { appWidgetId ->


val intent = Intent(context, PylonsWidgetService::class.java).apply {
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
data = Uri.parse(toUri(Intent.URI_INTENT_SCHEME))
}
val views = RemoteViews(context.packageName, R.layout.pylons_widget_layout).apply {
setRemoteAdapter(R.id.grid_view, intent)

setEmptyView(R.id.grid_view, R.id.empty_view)
}

appWidgetManager.updateAppWidget(appWidgetId, views)

}

super.onUpdate(context, appWidgetManager, appWidgetIds)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package tech.pylons.flutter_wallet

import android.content.Context
import android.content.Intent
import android.widget.RemoteViews
import android.widget.RemoteViewsService
import androidx.core.net.toUri
import tech.pylons.wallet.Pigeon
import tech.pylons.wallet.R


class PylonsWidgetService : RemoteViewsService() {

private lateinit var collectionsApi: Pigeon.CollectionsApi

override fun onGetViewFactory(intent: Intent): RemoteViewsFactory {
return GridRemoteViewsFactory(this.applicationContext, intent, collectionsApi)
}
}

class GridRemoteViewsFactory(
private val context: Context,
intent: Intent,
private val collectionsApi: Pigeon.CollectionsApi
) : RemoteViewsService.RemoteViewsFactory {
private var count: Int = 6

private lateinit var widgetItems: List<Pigeon.NFTMessage>

override fun onCreate() {
widgetItems = collectionsApi.getCollection()

}

override fun getViewAt(position: Int): RemoteViews {

return RemoteViews(context.packageName, R.layout.nft_image).apply {
setImageViewUri(R.id.nft, widgetItems[position].imageUrl.toUri())
}
}

override fun getLoadingView(): RemoteViews? {
return null
}

override fun getViewTypeCount(): Int {
return 1
}

override fun getItemId(position: Int): Long {
return position.toLong()
}

override fun hasStableIds(): Boolean {
return true
}

override fun onDataSetChanged() {
}

override fun onDestroy() {
}

override fun getCount(): Int {
return count
}


// See the RemoteViewsFactory API reference for the full list of methods to
// implement.

}
6 changes: 6 additions & 0 deletions wallet/android/app/src/main/res/layout/nft_image.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nft"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="centerCrop"
/>
19 changes: 19 additions & 0 deletions wallet/android/app/src/main/res/layout/pylons_widget_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:id="@+id/grid_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numColumns = "3"
android:columnWidth = "80dp" />
<TextView
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Widget Empty"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
</FrameLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="40dp"
android:minHeight="40dp"
android:updatePeriodMillis="86400000"
android:initialLayout="@layout/pylons_widget_layout"
android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen">
</appwidget-provider>
1 change: 1 addition & 0 deletions wallet/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/Contents/Home
Loading