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

#32 Implement demo app shortcuts #33

Merged
merged 1 commit into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 18 additions & 11 deletions client/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jraska.github.client">
package="com.jraska.github.client">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name=".GitHubClientApp"
Expand All @@ -16,35 +16,42 @@
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts"/>
</activity>
<activity
android:name=".ui.UserDetailActivity"
android:theme="@style/AppTheme.NoActionBar" />
android:theme="@style/AppTheme.NoActionBar"/>
<activity
android:name=".ui.RepoDetailActivity"
android:theme="@style/AppTheme.NoActionBar" />
android:theme="@style/AppTheme.NoActionBar"/>
<activity android:name=".ui.UriHandlerActivity">
<intent-filter android:label="@string/app_name">
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.VIEW"/>

<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="github.com"
android:pathPattern="/.*"
android:scheme="https" />
android:scheme="https"/>
</intent-filter>
</activity>

<service android:name=".push.PushHandleService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>

<activity android:name=".ui.ShortcutHandlerActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.jraska.github.client;

import android.arch.lifecycle.ViewModel;

import com.jraska.github.client.analytics.EventAnalytics;
import com.jraska.github.client.ui.ShortcutHandlerModel;

import dagger.Module;
import dagger.Provides;
import dagger.multibindings.ClassKey;
Expand Down Expand Up @@ -29,4 +33,12 @@ public static WebLinkLauncher webLinkLauncher(TopActivityProvider provider) {
public static ViewModel uriHandlerViewModel(DeepLinkHandler deepLinkHandler) {
return new UriHandlerViewModel(deepLinkHandler);
}

@Provides
@IntoMap
@ClassKey(ShortcutHandlerModel.class)
public static ViewModel uriShortcutViewModel(DeepLinkLauncher deepLinkHandler,
EventAnalytics eventAnalytics) {
return new ShortcutHandlerModel(deepLinkHandler, eventAnalytics);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.jraska.github.client.ui;

import android.os.Bundle;

import okhttp3.HttpUrl;

public class ShortcutHandlerActivity extends BaseActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ShortcutHandlerModel handlerModel = viewModel(ShortcutHandlerModel.class);

HttpUrl httpUrl = HttpUrl.parse(getIntent().getData().toString());
handlerModel.handleDeepLink(httpUrl);

finish();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.jraska.github.client.ui;

import android.arch.lifecycle.ViewModel;

import com.jraska.github.client.DeepLinkLauncher;
import com.jraska.github.client.analytics.AnalyticsEvent;
import com.jraska.github.client.analytics.EventAnalytics;

import okhttp3.HttpUrl;

public final class ShortcutHandlerModel extends ViewModel {
private final DeepLinkLauncher deepLinkLauncher;
private final EventAnalytics eventAnalytics;

public ShortcutHandlerModel(DeepLinkLauncher deepLinkLauncher, EventAnalytics eventAnalytics) {
this.deepLinkLauncher = deepLinkLauncher;
this.eventAnalytics = eventAnalytics;
}

void handleDeepLink(HttpUrl url) {
AnalyticsEvent event = AnalyticsEvent.builder("shortcut_clicked")
.addProperty("shortcut", url.toString())
.build();

eventAnalytics.report(event);

deepLinkLauncher.launch(url);
}
}
12 changes: 12 additions & 0 deletions client/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@
<string name="repos_contributed">Contributed repositories</string>
<string name="repo_detail_language_used_template">Language: %s</string>
<string name="repo_detail_issues_template">Issues Count: %s</string>

<string name="shortcut_users_short_label">Users</string>
<string name="shortcut_users_long_label">Browse Users</string>
<string name="shortcut_users_disabled_message">No longer available :(</string>

<string name="shortcut_jraska_short_label">Me</string>
<string name="shortcut_jraska_long_label">Josef Raska</string>
<string name="shortcut_jraska_disabled_message">No longer available :(</string>

<string name="shortcut_jake_short_label">Jake</string>
<string name="shortcut_jake_long_label">Jake Wharton</string>
<string name="shortcut_jake_disabled_message">No longer available :(</string>
</resources>
48 changes: 48 additions & 0 deletions client/src/main/res/xml/shortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="users"
android:enabled="true"
android:icon="@drawable/ic_github_48dp"
android:shortcutShortLabel="@string/shortcut_users_short_label"
android:shortcutLongLabel="@string/shortcut_users_long_label"
android:shortcutDisabledMessage="@string/shortcut_users_disabled_message">
<!-- TODO(josef): It is working now only for development app, this will probably stay development app -->
<intent
android:action="android.intent.action.VIEW"
android:data="https://github.com/users"
android:targetPackage="com.jraska.github.client.dev"
android:targetClass="com.jraska.github.client.ui.ShortcutHandlerActivity" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
<shortcut
android:shortcutId="users/jraska"
android:enabled="true"
android:icon="@drawable/ic_watchers_black_48dp"
android:shortcutShortLabel="@string/shortcut_jraska_short_label"
android:shortcutLongLabel="@string/shortcut_jraska_long_label"
android:shortcutDisabledMessage="@string/shortcut_jraska_disabled_message">
<intent
android:action="android.intent.action.VIEW"
android:data="https://github.com/jraska"
android:targetPackage="com.jraska.github.client.dev"
android:targetClass="com.jraska.github.client.ui.ShortcutHandlerActivity" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
<shortcut
android:shortcutId="users/JakeWharton"
android:enabled="true"
android:icon="@drawable/ic_admin_24dp"
android:shortcutShortLabel="@string/shortcut_jake_short_label"
android:shortcutLongLabel="@string/shortcut_jake_long_label"
android:shortcutDisabledMessage="@string/shortcut_jake_disabled_message">
<intent
android:action="android.intent.action.VIEW"
android:data="https://github.com/JakeWharton"
android:targetPackage="com.jraska.github.client.dev"
android:targetClass="com.jraska.github.client.ui.ShortcutHandlerActivity" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>