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

Added KiwiIRC as WebView component #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions app/src/main/assets/chat.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="fr">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<!-- seems like the font cannot be changed in KiwiIRC without writing a full theme, so loading the CSS below is useless-->
<!--
<link rel="stylesheet" href="stylesheet.css" type="text/css" charset="utf-8" /> -->

</head>

<body>
<div style="height: auto">
<iframe src="https://kiwiirc.com/nextclient/?theme=dark#irc://irc.rizon.net:+6697/#r/a/dio"
style="border:0; width:100%; height:100%; position: absolute; top: 0px; left: 0px">
</iframe>
</div>

</body>

</html>
19 changes: 18 additions & 1 deletion app/src/main/java/io/r_a_d/radio/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.webkit.URLUtil;

import android.webkit.WebView; // used for KiwiIRC embedding

import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
Expand Down Expand Up @@ -56,6 +59,8 @@ public class ActivityMain extends AppCompatActivity implements ViewPager.OnPageC
private boolean firstSearchClick = true;
private boolean newsSet = false;
private boolean m_bound = false;
private boolean isChatLoaded = false;

private ViewPager viewPager;
private JSONScraperTask jsonTask = new JSONScraperTask(this, 0);
private DJImageTask djimageTask = new DJImageTask(this);
Expand All @@ -66,6 +71,7 @@ public class ActivityMain extends AppCompatActivity implements ViewPager.OnPageC
private Requestor mRequestor;
private View searchFooter;
private RadioService m_service;
private WebViewChat webViewChat;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -76,7 +82,7 @@ protected void onCreate(Bundle savedInstanceState) {

viewPager = findViewById(R.id.viewpager);
viewPager.setAdapter(new CustomPagerAdapter(this));
viewPager.setOffscreenPageLimit(3);
viewPager.setOffscreenPageLimit(4);

viewPager.addOnPageChangeListener(this);

Expand Down Expand Up @@ -105,6 +111,7 @@ public void run() {

if (PlayerState.isServiceStarted())
bindToService();

}


Expand Down Expand Up @@ -166,6 +173,16 @@ public void onPageSelected(int position) {
if(!newsSet)
scrapeNews(NEWS_API);
break;
case R.id.chat_page:
title_text.setText("Chat");
if (this.isChatLoaded == false)
{
WebView webView = findViewById(R.id.chat_webview);
this.webViewChat = new WebViewChat(webView);
this.webViewChat.start();
this.isChatLoaded = true;
}
break;
}
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/io/r_a_d/radio/ModelObjectMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public enum ModelObjectMain {

NOWPLAYING(R.string.now_playing, R.layout.now_playing),
REQUESTS(R.string.requests, R.layout.requests),
NEWS(R.string.news, R.layout.news);
NEWS(R.string.news, R.layout.news),
CHAT(R.string.chat, R.layout.chat);

private int mTitleResId;
private int mLayoutResId;
Expand Down
52 changes: 52 additions & 0 deletions app/src/main/java/io/r_a_d/radio/WebViewChat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.r_a_d.radio;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class WebViewChat {

private WebView webView;

public WebViewChat(WebView webView)
{
this.webView = webView;
}

public void start(){

WebSettings webSetting = this.webView.getSettings();
webSetting.setJavaScriptEnabled(true);
webSetting.setSupportZoom(false);

/* TODO: in the future, it could be nice to have a parameters screen where you can:
- Set the text zoom
- Set your username (to not type it every time, would it be possible?)
- Hide the chat?
- do more? */
webSetting.setTextZoom(90);

webSetting.setSupportMultipleWindows(true);
// needs to open target="_blank" links as KiwiIRC links have this attribute.
// shamelessly ripped off https://stackoverflow.com/questions/18187714/android-open-target-blank-links-in-webview-with-external-browser
this.webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, android.os.Message resultMsg)
{
WebView.HitTestResult result = view.getHitTestResult();
String data = result.getExtra();
Context context = view.getContext();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data));
context.startActivity(browserIntent);
return false;
}
});

webView.loadUrl("file:///android_asset/chat.html");
}

}
21 changes: 21 additions & 0 deletions app/src/main/res/layout/chat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:id="@+id/chat_page" >

<!--
Yattoz - this is a simple embedded WebView to display KiwiIRC in the app.
KiwiIRC is a decent IRC, but the website is clunky and you must scroll a lot.
This WebView is just the size of the screen, to make it practical.
-->

<WebView
android:id="@+id/chat_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</FrameLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
<string name="request_page">Request</string>
<string name="news_page">News</string>
<string name="schedule_page">Schedule</string>
<string name="chat_page">Chat</string>

<string name="title_activity_slided">LeftSlider</string>
<string name="now_playing">NOWPLAYING</string>
<string name="requests">REQUESTS</string>
<string name="news">NEWS</string>
<string name="chat">CHAT</string>

<string name="connecting">Connecting...</string>
<string name="dots">...</string>

Expand Down