Commit 47c04734 authored by Sajal Narang's avatar Sajal Narang

Implement deep links

parent a3d31364
...@@ -35,7 +35,52 @@ ...@@ -35,7 +35,52 @@
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTask" android:launchMode="singleTask"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" /> android:theme="@style/AppTheme.NoActionBar">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="insti.app"
android:pathPattern="/org/.*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="insti.app"
android:pathPattern="/user/.*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="insti.app"
android:pathPattern="/org/.*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="insti.app"
android:pathPattern="/user/.*" />
</intent-filter>
</activity>
<activity <activity
android:name=".LoginActivity" android:name=".LoginActivity"
android:launchMode="singleTask" android:launchMode="singleTask"
......
...@@ -23,11 +23,12 @@ import android.widget.ImageView; ...@@ -23,11 +23,12 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import app.insti.api.UnsafeOkHttpClient; import app.insti.api.UnsafeOkHttpClient;
import app.insti.data.Body;
import app.insti.data.User; import app.insti.data.User;
import app.insti.fragment.BodyFragment;
import app.insti.fragment.CalendarFragment; import app.insti.fragment.CalendarFragment;
import app.insti.fragment.FeedFragment; import app.insti.fragment.FeedFragment;
import app.insti.fragment.MapFragment; import app.insti.fragment.MapFragment;
...@@ -78,7 +79,46 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -78,7 +79,46 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
feedFragment = new FeedFragment(); feedFragment = new FeedFragment();
updateFragment(feedFragment); updateFragment(feedFragment);
// fetchNotifications(); Intent appLinkIntent = getIntent();
handleIntent(appLinkIntent);
}
private void handleIntent(Intent appLinkIntent) {
String appLinkAction = appLinkIntent.getAction();
String appLinkData = appLinkIntent.getDataString();
if (Intent.ACTION_VIEW.equals(appLinkAction) && appLinkData != null) {
switch (getType(appLinkData)) {
case "body":
Body body = new Body(getID(appLinkData));
BodyFragment bodyFragment = BodyFragment.newInstance(body);
updateFragment(bodyFragment);
break;
case "user":
ProfileFragment profileFragment = ProfileFragment.newInstance(getID(appLinkData));
updateFragment(profileFragment);
}
}
}
private String getID(String appLinkData) {
if (appLinkData.charAt(appLinkData.length() - 1) == '/')
appLinkData = appLinkData.substring(0, appLinkData.length() - 1);
switch (getType(appLinkData)) {
case "body":
return appLinkData.substring(appLinkData.indexOf("org") + 4);
case "user":
return appLinkData.substring(appLinkData.indexOf("user") + 5);
}
return null;
}
private String getType(String appLinkData) {
if (appLinkData.startsWith("http://insti.app/org/") || appLinkData.startsWith("https://insti.app/org/")) {
return "body";
} else if (appLinkData.startsWith("http://insti.app/user/") || appLinkData.startsWith("https://insti.app/user/")) {
return "user";
}
return null;
} }
@Override @Override
...@@ -192,8 +232,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -192,8 +232,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if (session.isLoggedIn()) { if (session.isLoggedIn()) {
TrainingBlogFragment trainingBlogFragment = new TrainingBlogFragment(); TrainingBlogFragment trainingBlogFragment = new TrainingBlogFragment();
updateFragment(trainingBlogFragment); updateFragment(trainingBlogFragment);
} } else {
else{
Toast.makeText(this, Constants.LOGIN_MESSAGE, Toast.LENGTH_LONG).show(); Toast.makeText(this, Constants.LOGIN_MESSAGE, Toast.LENGTH_LONG).show();
} }
break; break;
......
...@@ -2,6 +2,7 @@ package app.insti.data; ...@@ -2,6 +2,7 @@ package app.insti.data;
import android.arch.persistence.room.ColumnInfo; import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity; import android.arch.persistence.room.Entity;
import android.arch.persistence.room.Ignore;
import android.arch.persistence.room.PrimaryKey; import android.arch.persistence.room.PrimaryKey;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
...@@ -56,6 +57,11 @@ public class Body { ...@@ -56,6 +57,11 @@ public class Body {
@SerializedName("roles") @SerializedName("roles")
List<Role> bodyRoles; List<Role> bodyRoles;
@Ignore
public Body(@NonNull String bodyID) {
this.bodyID = bodyID;
}
public Body(String bodyID, String bodyStrID, String bodyName, String bodyShortDescription, String bodyDescription, String bodyImageURL, List<Body> bodyChildren, List<Body> bodyParents, List<Event> bodyEvents, int bodyFollowersCount, String bodyWebsiteURL, String bodyBlogURL, boolean bodyUserFollows, List<Role> bodyRoles) { public Body(String bodyID, String bodyStrID, String bodyName, String bodyShortDescription, String bodyDescription, String bodyImageURL, List<Body> bodyChildren, List<Body> bodyParents, List<Event> bodyEvents, int bodyFollowersCount, String bodyWebsiteURL, String bodyBlogURL, boolean bodyUserFollows, List<Role> bodyRoles) {
this.bodyID = bodyID; this.bodyID = bodyID;
this.bodyStrID = bodyStrID; this.bodyStrID = bodyStrID;
......
...@@ -15,6 +15,7 @@ import android.view.ViewGroup; ...@@ -15,6 +15,7 @@ import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import java.util.List; import java.util.List;
...@@ -140,5 +141,11 @@ public class ProfileFragment extends BaseFragment { ...@@ -140,5 +141,11 @@ public class ProfileFragment extends BaseFragment {
getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE); getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
} }
public static ProfileFragment newInstance(String userID) {
ProfileFragment fragment = new ProfileFragment();
Bundle args = new Bundle();
args.putString(Constants.USER_ID, userID);
fragment.setArguments(args);
return fragment;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment