Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
339a790b
Commit
339a790b
authored
Dec 11, 2018
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use java.net.URL for parsing (fix #259)
parent
5d5cfe6e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
17 deletions
+24
-17
app/src/main/java/app/insti/activity/MainActivity.java
app/src/main/java/app/insti/activity/MainActivity.java
+24
-17
No files found.
app/src/main/java/app/insti/activity/MainActivity.java
View file @
339a790b
...
...
@@ -42,6 +42,8 @@ import com.google.gson.JsonElement;
import
com.google.gson.JsonObject
;
import
com.squareup.picasso.Picasso
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.List
;
import
app.insti.Constants
;
...
...
@@ -378,27 +380,32 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
private
String
getID
(
String
appLinkData
)
{
if
(
appLinkData
.
charAt
(
appLinkData
.
length
()
-
1
)
==
'/'
)
appLinkData
=
appLinkData
.
substring
(
0
,
appLinkData
.
length
()
-
1
);
switch
(
getType
(
appLinkData
))
{
case
DATA_TYPE_BODY:
return
appLinkData
.
substring
(
appLinkData
.
indexOf
(
"org"
)
+
4
);
case
DATA_TYPE_USER:
return
appLinkData
.
substring
(
appLinkData
.
indexOf
(
"user"
)
+
5
);
case
DATA_TYPE_EVENT:
return
appLinkData
.
substring
(
appLinkData
.
indexOf
(
"event"
)
+
6
);
try
{
/* Parse URL and get second part */
String
[]
parts
=
new
URL
(
appLinkData
).
getPath
().
split
(
"/"
);
if
(
parts
.
length
>=
3
)
{
return
parts
[
2
];
}
}
catch
(
MalformedURLException
ignored
)
{}
return
null
;
}
private
String
getType
(
String
appLinkData
)
{
if
(
appLinkData
.
contains
(
"://insti.app/org/"
))
{
try
{
/* Parse URL and check length */
String
[]
parts
=
new
URL
(
appLinkData
).
getPath
().
split
(
"/"
);
if
(
parts
.
length
<
2
)
return
null
;
/* Map to proper data type */
switch
(
parts
[
1
].
toLowerCase
())
{
case
"org"
:
return
DATA_TYPE_BODY
;
}
else
if
(
appLinkData
.
contains
(
"://insti.app/user/"
))
{
return
DATA_TYPE_USER
;
}
else
if
(
appLinkData
.
contains
(
"://insti.app/event/"
))
{
case
"event"
:
return
DATA_TYPE_EVENT
;
case
"user"
:
return
DATA_TYPE_USER
;
}
}
catch
(
MalformedURLException
ignored
)
{}
return
null
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment