Skip to content

Commit 2f25a52

Browse files
committed
Initial commit of Java code
Change-Id: I29bf104bad9c029c3ccc06f7ae316257f9a7fb88
1 parent 813ba42 commit 2f25a52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1238
-1
lines changed

dl-invites/app/build.gradle

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
5+
android {
6+
compileSdkVersion 28
7+
8+
defaultConfig {
9+
applicationId "com.google.firebase.dynamicinvites"
10+
minSdkVersion 19
11+
targetSdkVersion 28
12+
versionCode 1
13+
versionName "1.0"
14+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
}
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
}
23+
24+
dependencies {
25+
implementation 'com.android.support:support-v4:28.0.0'
26+
implementation 'com.android.support:appcompat-v7:28.0.0'
27+
implementation 'com.android.support:cardview-v7:28.0.0'
28+
implementation 'com.android.support:recyclerview-v7:28.0.0'
29+
implementation 'com.google.firebase:firebase-dynamic-links:16.1.5'
30+
31+
implementation 'com.android.support:design:28.0.0'
32+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
33+
34+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
35+
}

dl-invites/app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.google.firebase.dynamicinvites">
5+
6+
<application
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme"
13+
tools:ignore="GoogleAppIndexingWarning">
14+
<activity
15+
android:name=".MainActivity"
16+
android:label="Invite Members">
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
23+
<activity
24+
android:name=".AdvancedActivity"
25+
android:label="Invite Members">
26+
<intent-filter>
27+
<action android:name="android.intent.action.MAIN" />
28+
<category android:name="android.intent.category.LAUNCHER" />
29+
</intent-filter>
30+
</activity>
31+
</application>
32+
33+
</manifest>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.google.firebase.dynamicinvites;
2+
3+
import android.support.v7.app.AppCompatActivity;
4+
import android.os.Bundle;
5+
import android.view.View;
6+
7+
import com.google.firebase.dynamicinvites.presenter.InvitePresenter;
8+
9+
public class AdvancedActivity extends AppCompatActivity implements ShareDialogFragment.Listener {
10+
11+
@Override
12+
protected void onCreate(Bundle savedInstanceState) {
13+
super.onCreate(savedInstanceState);
14+
setContentView(R.layout.activity_advanced);
15+
16+
findViewById(R.id.button_share).setOnClickListener(new View.OnClickListener() {
17+
@Override
18+
public void onClick(View view) {
19+
ShareDialogFragment.newInstance().show(getSupportFragmentManager(), "dialog");
20+
}
21+
});
22+
}
23+
24+
@Override
25+
public void onItemClicked(InvitePresenter presenter) {
26+
presenter.sendInvite(this);
27+
}
28+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.google.firebase.dynamicinvites;
2+
3+
import android.content.Intent;
4+
import android.net.Uri;
5+
import android.os.Bundle;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.view.View;
8+
9+
import com.google.firebase.dynamiclinks.DynamicLink;
10+
import com.google.firebase.dynamiclinks.FirebaseDynamicLinks;
11+
12+
public class MainActivity extends AppCompatActivity {
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
setContentView(R.layout.activity_main);
18+
19+
findViewById(R.id.button_share).setOnClickListener(new View.OnClickListener() {
20+
@Override
21+
public void onClick(View view) {
22+
onShareClicked();
23+
}
24+
});
25+
}
26+
27+
28+
private Uri generateContentLink() {
29+
Uri baseUrl = Uri.parse("https://your-custom-name.page.link");
30+
String domain = "https://your-app.page.link";
31+
32+
DynamicLink link = FirebaseDynamicLinks.getInstance()
33+
.createDynamicLink()
34+
.setLink(baseUrl)
35+
.setDomainUriPrefix(domain)
36+
.setIosParameters(new DynamicLink.IosParameters.Builder("com.your.bundleid").build())
37+
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder("com.your.packageName").build())
38+
.buildDynamicLink();
39+
40+
return link.getUri();
41+
}
42+
43+
private void onShareClicked() {
44+
Uri link = generateContentLink();
45+
46+
Intent intent = new Intent(Intent.ACTION_SEND);
47+
intent.setType("text/plain");
48+
intent.putExtra(Intent.EXTRA_TEXT, link.toString());
49+
50+
startActivity(Intent.createChooser(intent, "Share Link"));
51+
}
52+
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
package com.google.firebase.dynamicinvites;
2+
3+
import android.content.Context;
4+
import android.os.Bundle;
5+
import android.support.annotation.NonNull;
6+
import android.support.annotation.Nullable;
7+
import android.support.design.widget.BottomSheetDialogFragment;
8+
import android.support.v4.app.Fragment;
9+
import android.support.v7.widget.LinearLayoutManager;
10+
import android.support.v7.widget.RecyclerView;
11+
import android.view.LayoutInflater;
12+
import android.view.View;
13+
import android.view.ViewGroup;
14+
import android.widget.ImageView;
15+
import android.widget.TextView;
16+
17+
import com.google.firebase.dynamicinvites.presenter.InvitePresenter;
18+
import com.google.firebase.dynamicinvites.presenter.CopyPresenter;
19+
import com.google.firebase.dynamicinvites.presenter.EmailPresenter;
20+
import com.google.firebase.dynamicinvites.presenter.MessagePresenter;
21+
import com.google.firebase.dynamicinvites.presenter.MorePresenter;
22+
import com.google.firebase.dynamicinvites.presenter.SocialPresenter;
23+
24+
import java.util.Arrays;
25+
import java.util.List;
26+
27+
/**
28+
* A fragment that shows a list of items as a modal bottom sheet.
29+
*
30+
* <p>You can show this modal bottom sheet from your activity like this:
31+
*
32+
* <pre>
33+
* ShareDialogFragment.newInstance().show(getSupportFragmentManager(), "dialog");
34+
* </pre>
35+
*
36+
* <p>You activity (or fragment) needs to implement {@link ShareDialogFragment.Listener}.
37+
*/
38+
public class ShareDialogFragment extends BottomSheetDialogFragment {
39+
40+
private Listener mListener;
41+
42+
public static ShareDialogFragment newInstance() {
43+
final ShareDialogFragment fragment = new ShareDialogFragment();
44+
final Bundle args = new Bundle();
45+
fragment.setArguments(args);
46+
return fragment;
47+
}
48+
49+
@Nullable
50+
@Override
51+
public View onCreateView(LayoutInflater inflater,
52+
@Nullable ViewGroup container,
53+
@Nullable Bundle savedInstanceState) {
54+
return inflater.inflate(R.layout.fragment_item_list_dialog, container, false);
55+
}
56+
57+
@Override
58+
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
59+
// TODO: Non-null content
60+
List<InvitePresenter> presenters = Arrays.asList(
61+
new EmailPresenter(true, null),
62+
new SocialPresenter(true, null),
63+
new MessagePresenter(true, null),
64+
new CopyPresenter(true, null),
65+
new MorePresenter(true, null)
66+
);
67+
68+
RecyclerView recyclerView = (RecyclerView) view;
69+
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
70+
recyclerView.setAdapter(new ItemAdapter(presenters));
71+
}
72+
73+
@Override
74+
public void onAttach(Context context) {
75+
super.onAttach(context);
76+
final Fragment parent = getParentFragment();
77+
if (parent != null) {
78+
mListener = (Listener) parent;
79+
} else {
80+
mListener = (Listener) context;
81+
}
82+
}
83+
84+
@Override
85+
public void onDetach() {
86+
mListener = null;
87+
super.onDetach();
88+
}
89+
90+
public interface Listener {
91+
void onItemClicked(InvitePresenter presenter);
92+
}
93+
94+
private class ViewHolder extends RecyclerView.ViewHolder {
95+
96+
private final TextView text;
97+
private final ImageView icon;
98+
99+
private InvitePresenter presenter;
100+
101+
ViewHolder(LayoutInflater inflater, ViewGroup parent) {
102+
super(inflater.inflate(R.layout.item_share_method, parent, false));
103+
104+
text = itemView.findViewById(R.id.item_name);
105+
icon = itemView.findViewById(R.id.item_icon);
106+
107+
itemView.setOnClickListener(
108+
new View.OnClickListener() {
109+
@Override
110+
public void onClick(View v) {
111+
if (mListener != null) {
112+
mListener.onItemClicked(presenter);
113+
dismiss();
114+
}
115+
}
116+
});
117+
}
118+
119+
void bind(InvitePresenter presenter) {
120+
this.presenter = presenter;
121+
122+
text.setText(presenter.name);
123+
icon.setImageResource(presenter.icon);
124+
}
125+
}
126+
127+
private class ItemAdapter extends RecyclerView.Adapter<ViewHolder> {
128+
129+
private List<InvitePresenter> items;
130+
131+
ItemAdapter(List<InvitePresenter> items) {
132+
this.items = items;
133+
}
134+
135+
@NonNull
136+
@Override
137+
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
138+
return new ViewHolder(LayoutInflater.from(parent.getContext()), parent);
139+
}
140+
141+
@Override
142+
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
143+
InvitePresenter presenter = items.get(position);
144+
holder.bind(presenter);
145+
}
146+
147+
@Override
148+
public int getItemCount() {
149+
return items.size();
150+
}
151+
}
152+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.google.firebase.dynamicinvites.model;
2+
3+
import android.net.Uri;
4+
import android.support.annotation.NonNull;
5+
import android.support.annotation.Nullable;
6+
7+
// [START ddl_invite_content]
8+
/**
9+
* The content of an invitation, with optional fields to accommodate all presenters.
10+
* This type could be modified to also include an image, for sending invites over email.
11+
*/
12+
public class InviteContent {
13+
14+
/** The subject of the message. Not used for invites without subjects, like SMS. **/
15+
@Nullable
16+
public final String subject;
17+
18+
/** The body of the message. Indispensable content should go here. **/
19+
@Nullable
20+
public final String body;
21+
22+
/** The URL containing the link to invite. In link-copy cases, only this field will be used. **/
23+
@NonNull
24+
public final Uri link;
25+
26+
public InviteContent(@Nullable String subject, @Nullable String body, @NonNull Uri link) {
27+
// [START_EXCLUDE]
28+
this.subject = subject;
29+
this.body = body;
30+
this.link = link;
31+
// [END_EXCLUDE]
32+
}
33+
34+
}
35+
// [END ddl_invite_content]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.google.firebase.dynamicinvites.presenter;
2+
3+
import com.google.firebase.dynamicinvites.R;
4+
import com.google.firebase.dynamicinvites.model.InviteContent;
5+
6+
public class CopyPresenter extends InvitePresenter {
7+
8+
public CopyPresenter(boolean isAvailable, InviteContent content) {
9+
super("Copy Link", R.drawable.ic_content_copy_black_24dp, isAvailable, content);
10+
}
11+
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.google.firebase.dynamicinvites.presenter;
2+
3+
import com.google.firebase.dynamicinvites.R;
4+
import com.google.firebase.dynamicinvites.model.InviteContent;
5+
6+
public class EmailPresenter extends InvitePresenter {
7+
8+
public EmailPresenter(boolean isAvailable, InviteContent content) {
9+
super("Email", R.drawable.ic_email_black_24dp, isAvailable, content);
10+
}
11+
12+
}

0 commit comments

Comments
 (0)