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

Need your help! #1

Open
nino-finch opened this issue Sep 3, 2021 · 16 comments
Open

Need your help! #1

nino-finch opened this issue Sep 3, 2021 · 16 comments

Comments

@nino-finch
Copy link

Hi sorry this is not really a bug report for AusWeather repo but I couldn't find any other way to reach out to you.

Was looking at your post here ABausG/home_widget#34 and was curious if you could share more on how you implement the ImageView on the homewidget library?

Thanks and really appreciate your response!

p.s: sorry again to use this inappropriately, I'd be very happy to connect through email too! My email is [email protected]

@Viktohblake
Copy link

Did you get to do it? I'm also having that issue

@roly151
Copy link
Owner

roly151 commented Aug 18, 2022

Hi, yes, you can edit this function to turn an image into a string, and then send the string to the android widget

Future<String> serialiseImage(String icon) async { ByteData bytes = (await rootBundle.load('images/icons/$icon.png')); var buffer = bytes.buffer; return base64Encode(Uint8List.view(buffer)); }

Then deserialise the image in the WidgetProvider using Kotlin:

val image = widgetData.getString("imageName", null) if (image != null) { val lw02_imageBytes = Base64.decode(widgetData.getString("imageName", null), Base64.DEFAULT) val lw02_decodedImage = BitmapFactory.decodeByteArray(lw02_imageBytes, 0, lw02_imageBytes.size) setImageViewBitmap(R.id.lw02_todayIcon, lw02_decodedImage) }

@Viktohblake
Copy link

thanks, working!

@Viktohblake
Copy link

please do you have a working ios process for this?

@Viktohblake
Copy link

Hi, yes, you can edit this function to turn an image into a string, and then send the string to the android widget

Future<String> serialiseImage(String icon) async { ByteData bytes = (await rootBundle.load('images/icons/$icon.png')); var buffer = bytes.buffer; return base64Encode(Uint8List.view(buffer)); }

Then deserialise the image in the WidgetProvider using Kotlin:

val image = widgetData.getString("imageName", null) if (image != null) { val lw02_imageBytes = Base64.decode(widgetData.getString("imageName", null), Base64.DEFAULT) val lw02_decodedImage = BitmapFactory.decodeByteArray(lw02_imageBytes, 0, lw02_imageBytes.size) setImageViewBitmap(R.id.lw02_todayIcon, lw02_decodedImage) }

Please do you have a working ios process for this?

@roly151
Copy link
Owner

roly151 commented Aug 29, 2022

Hi, I don't have code for iOS yet. I had issues with the widget showing up on an iOS device, which I don't think are related to the homewidget package. I followed the instructions on the homewidget GitHub page: https://github.com/ABausG/home_widget

The code I had in the widget swift file is below. It was/is test code to get a basic widget working. But as I said, on an iOS device or emulator, the widget did not show up to be able to add to the home page. I haven't worked on this yet as I'm redoing my app from the ground up to be more efficient. Will get to this in time and post more once I do - but it will be a while.

`
import WidgetKit
import SwiftUI

struct Provider: TimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date())
}

func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
    let entry = SimpleEntry(date: Date())
    completion(entry)
}

func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
    var entries: [SimpleEntry] = []

    let currentDate = Date()
    for hourOffset in 0 ..< 5 {
        let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
        let entry = SimpleEntry(date: entryDate)
        entries.append(entry)
    }

    let timeline = Timeline(entries: entries, policy: .atEnd)
    completion(timeline)
}

}

struct SimpleEntry: TimelineEntry {
let date: Date
}

struct LocalWeatherWidgetEntryView : View {
var entry: Provider.Entry

var body: some View {
    Text(entry.date, style: .time)
}

}

@main
struct LocalWeatherWidget: Widget {
let kind: String = "LocalWeatherWidget"

var body: some WidgetConfiguration {
    StaticConfiguration(kind: kind, provider: Provider()) { entry in
        LocalWeatherWidgetEntryView(entry: entry)
    }
    .configurationDisplayName("My Widget")
    .description("This is an example widget.")
}

}

struct LocalWeatherWidget_Previews: PreviewProvider {
static var previews: some View {
LocalWeatherWidgetEntryView(entry: SimpleEntry(date: Date()))
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
}
`

@roly151
Copy link
Owner

roly151 commented Aug 29, 2022

@nino-finch might be able to help, as I'm pretty sure he got it working.

@Viktohblake
Copy link

Hi, I don't have code for iOS yet. I had issues with the widget showing up on an iOS device, which I don't think are related to the homewidget package. I followed the instructions on the homewidget GitHub page: https://github.com/ABausG/home_widget

The code I had in the widget swift file is below. It was/is test code to get a basic widget working. But as I said, on an iOS device or emulator, the widget did not show up to be able to add to the home page. I haven't worked on this yet as I'm redoing my app from the ground up to be more efficient. Will get to this in time and post more once I do - but it will be a while.

` import WidgetKit import SwiftUI

struct Provider: TimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date()) }

func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> ()) {
    let entry = SimpleEntry(date: Date())
    completion(entry)
}

func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
    var entries: [SimpleEntry] = []

    let currentDate = Date()
    for hourOffset in 0 ..< 5 {
        let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
        let entry = SimpleEntry(date: entryDate)
        entries.append(entry)
    }

    let timeline = Timeline(entries: entries, policy: .atEnd)
    completion(timeline)
}

}

struct SimpleEntry: TimelineEntry { let date: Date }

struct LocalWeatherWidgetEntryView : View { var entry: Provider.Entry

var body: some View {
    Text(entry.date, style: .time)
}

}

@main struct LocalWeatherWidget: Widget { let kind: String = "LocalWeatherWidget"

var body: some WidgetConfiguration {
    StaticConfiguration(kind: kind, provider: Provider()) { entry in
        LocalWeatherWidgetEntryView(entry: entry)
    }
    .configurationDisplayName("My Widget")
    .description("This is an example widget.")
}

}

struct LocalWeatherWidget_Previews: PreviewProvider { static var previews: some View { LocalWeatherWidgetEntryView(entry: SimpleEntry(date: Date())) .previewContext(WidgetPreviewContext(family: .systemSmall)) } } `

THANKS FOR THIS @roly151 , REALLY APPRECIATE THE FAST RESPONSE

@Viktohblake
Copy link

@nino-finch might be able to help, as I'm pretty sure he got it working.

alright, I hope @nino-finch gets to see this and repond, thank you!

@Viktohblake
Copy link

@roly151 good day bro, i'm here again lol, sorry for disturbing.

Please I want to ask how you did the loadData() method for the widget?

@roly151
Copy link
Owner

roly151 commented Sep 1, 2022

@roly151 good day bro, i'm here again lol, sorry for disturbing.

Please I want to ask how you did the loadData() method for the widget?

Hi, Can you explain a bit more? I'm not quite sure what you need?

Cheers

@Viktohblake
Copy link

Okay, I want the qr code selected and sent to widget to stay fixed in the inapp qr code image view when the user closes and opens the app.

Let me elaborate a bit; normally the qr code i send to the widget stays fixed whether app is closes, but it's not the same for the inapp qr code image. So basically i'm trying to keep the qr code in the widget also in the app to show that yeah this is what is currently on your widget unless you want to change it.

Note: I use qr code generator, so I parse a text into a textfield and update the qr code, get the image and send to the widget, so by default when you open and close the app the qr code generator refreshes to a pre default qr code from the generator.

I do hope you understand. if not let me know.

@roly151
Copy link
Owner

roly151 commented Sep 5, 2022

If I understand you correctly, when you send the QR code to the widget, you also need to save the QR code image to file on the device? That way, when you close the app, it is saved, and you can load it when the app is opened?

Is that correct?

@Viktohblake
Copy link

Yes exactly.. that right.

@roly151
Copy link
Owner

roly151 commented Sep 26, 2022

You don't need home_widget for that. Just look up a package to save a file to the phone. Then when you load your app, check if there is a QR code saved to file and load that code then save it to the widget?

@Viktohblake
Copy link

I later got it to work by using Authentication and generate the qr code based on the current user signed in so the qr code always stays.
What I was trying to say is while i was generating the qr code locally using text, closing and opening the app clears the generated qr code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants