oryanm / TrelloWidget

Android widget for Trello's lists
MIT License
61 stars 24 forks source link

Link cards and boards to Trello app #2

Closed lack closed 8 years ago

lack commented 8 years ago

These 2 commits take advantage of the fact that the official Trello app intercepts ACTION_VIEW for all https://trello.com/* URIs, and will load a specific card or board.

We can fetch the card url easily and now include it in the Card object. Clicking on a card in the widget opens the card in Trello! I also ended up removing the now unused "CardActivity".

Boards are a bit trickier, since the widget config only stores the BoardList. We can fetch the Board based on the list ID, but this is tricky to do since I can't just drop it inline to the widget update without hitting an ANR.

So for now, only new widgets get the board link set up correctly so that clicking on the title opens the board in Trello - Existing widgets need to be removed and recreated to get re-linked up - But they do maintain the previous behavior of opening Trello itself (if configured to do so).

I will try to get to auto-updating the widget title link intent in a later change.

oryanm commented 8 years ago

is that behaviour documented somewhere? what happens if the officaial app is not installed on the device?

lack commented 8 years ago

It's documented only in that their app's manifest file specifically has these (via aapt dump):

        E: activity (line=180)
          A: android:theme(0x01010000)=@0x7f0c00a2
          A: android:label(0x01010001)=@0x7f080156
          A: android:name(0x01010003)="com.trello.UriHandlerActivity" (Raw: "com.trello.UriHandlerActivity")
          A: android:excludeFromRecents(0x01010017)=(type 0x12)0xffffffff
          E: intent-filter (line=185)
            A: android:autoVerify(0x010104ee)=(type 0x12)0xffffffff
            E: action (line=186)
              A: android:name(0x01010003)="android.intent.action.VIEW" (Raw: "android.intent.action.VIEW")
            E: category (line=188)
              A: android:name(0x01010003)="android.intent.category.DEFAULT" (Raw: "android.intent.category.DEFAULT")
            E: category (line=189)
              A: android:name(0x01010003)="android.intent.category.BROWSABLE" (Raw: "android.intent.category.BROWSABLE")
            E: data (line=191)
              A: android:scheme(0x01010027)="https" (Raw: "https")
              A: android:host(0x01010028)="trello.com" (Raw: "trello.com")
              A: android:pathPrefix(0x0101002b)="/board/" (Raw: "/board/")
            E: data (line=195)
              A: android:scheme(0x01010027)="https" (Raw: "https")
              A: android:host(0x01010028)="trello.com" (Raw: "trello.com")
              A: android:pathPrefix(0x0101002b)="/card/" (Raw: "/card/")
            E: data (line=199)
              A: android:scheme(0x01010027)="https" (Raw: "https")
              A: android:host(0x01010028)="trello.com" (Raw: "trello.com")
              A: android:pathPrefix(0x0101002b)="/c/" (Raw: "/c/")
            E: data (line=203)
              A: android:scheme(0x01010027)="https" (Raw: "https")
              A: android:host(0x01010028)="trello.com" (Raw: "trello.com")
              A: android:pathPrefix(0x0101002b)="/b/" (Raw: "/b/")
            E: data (line=207)
              A: android:scheme(0x01010027)="http" (Raw: "http")
              A: android:host(0x01010028)="trello.com" (Raw: "trello.com")
              A: android:pathPrefix(0x0101002b)="/confirm" (Raw: "/confirm")

So you can see that they'll catch https://trello.com/(b|board|c|card)/* and display those in the app. The Urls I use to link up to these are the actual url field of their own API model, so I think it's safe to assume they'll support these for the forseeable future.

As to what happens if the trello app isn't installed, it opens up trello.com in your mobile web browser either to the specified board or the card, which is a nice fallback!

oryanm commented 8 years ago

:+1: I'll accept this since it'll save a lot of effort reimplementing features that exist in the offical app.

However, this creates a small problem where if I press a card, edit it and then go back to the home screen, I'll not see the changes I've made until I press the refresh button / next update interval. Any idea on how can we know to refresh the wiget once the offical app is closed?

lack commented 8 years ago

That's an interesting problem... I wonder if there's a signal from Android when we arrive back at the home screen, from which we could force a refresh, or something like that?

lack commented 8 years ago

Or maybe polling more often, but only checking the board's 'dateLastActivity' to see if we really need to do a whole refresh or not? I'll play around with this some, as I have time...

oryanm commented 8 years ago

I guessing it's not possible by design. The best I could find was to use UsageStatsManager to find out if Trello was used recently. But I don't think that's a very good idea.

My concern about polling more often would be wake locks and battery drain and less about unnecessary refreshes. This isn't a huge deal so I wouldn't want to overcomplicate things just for that.