-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
- Loading branch information
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
app/src/main/java/org/ole/planet/myplanet/utilities/CustomClickableSpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.ole.planet.myplanet.utilities; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.text.style.ClickableSpan; | ||
import android.view.View; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import org.ole.planet.myplanet.ui.viewer.WebViewActivity; | ||
|
||
public class CustomClickableSpan extends ClickableSpan { | ||
private final String url; | ||
private final String title; | ||
private final Context context; | ||
|
||
public CustomClickableSpan(String url, String title, Context context) { | ||
this.url = url; | ||
this.title = title; | ||
this.context = context; | ||
} | ||
@Override | ||
public void onClick(@NonNull View widget) { | ||
openLinkInWebView(url, title); | ||
} | ||
|
||
private void openLinkInWebView(String link, String title) { | ||
if (link != null && !link.isEmpty()) { | ||
Intent webViewIntent = new Intent(context, WebViewActivity.class); | ||
webViewIntent.putExtra("title", title); | ||
webViewIntent.putExtra("link", link); | ||
context.startActivity(webViewIntent); | ||
} else { | ||
Utilities.toast(context, "Invalid link"); | ||
} | ||
} | ||
} |