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

Add Support for JuiceSSH #204

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions Android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ allprojects {
repositories {
jcenter()
google()
maven { url 'https://raw.github.com/Sonelli/maven/master' }
}
}

Expand Down
2 changes: 2 additions & 0 deletions Android/mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ dependencies {

implementation "com.android.support:appcompat-v7:27.1.1"
implementation 'com.android.support:support-v4:27.1.1'

implementation 'com.sonelli:juicessh-pluginlibrary:1.0.+@aar'
}

apply plugin: 'com.google.gms.google-services'
7 changes: 5 additions & 2 deletions Android/mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fi.iki.murgo.irssinotifier" >
xmlns:tools="http://schemas.android.com/tools"
package="fi.iki.murgo.irssinotifier">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="com.sonelli.juicessh.api.v1.permission.READ_CONNECTIONS" />
<!--
This was required on lower API levels but I guess not any more?
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
-->

<uses-sdk />

<application android:icon="@drawable/icon"
<application tools:replace="android:icon"
android:icon="@drawable/icon"
android:name="fi.iki.murgo.irssinotifier.IrssiNotifierApplication"
android:label="@string/app_name"
android:allowBackup="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ public boolean onCreateOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_irssi_connectbot).setEnabled(false);
}

if (!preferences.getJuiceSSHEnabled() || !IntentSniffer.isPackageAvailable(this, JuiceSSHLauncher.PACKAGE_JUICESSH)) {
menu.findItem(R.id.menu_juicessh).setVisible(false);
menu.findItem(R.id.menu_juicessh).setEnabled(false);
}

return true;
}

Expand All @@ -383,6 +388,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_irssi_connectbot) {
IrssiConnectbotLauncher.launchIrssiConnectbot(this);
//MessageGenerator.Flood(this);
} else if (item.getItemId() == R.id.menu_juicessh) {
JuiceSSHLauncher.launchJuiceSSH(this);
} else if (item.getItemId() == R.id.menu_settings) {
Intent settingsActivity = new Intent(this, SettingsActivity.class);
startActivity(settingsActivity);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

package fi.iki.murgo.irssinotifier;

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

public class JuiceSSHLauncher {
public static final String PACKAGE_JUICESSH = "com.sonelli.juicessh";

public static boolean launchJuiceSSH(Context context) {
if (!IntentSniffer.isPackageAvailable(context, JuiceSSHLauncher.PACKAGE_JUICESSH))
return false;

Preferences prefs = new Preferences(context);
String hostUUID = prefs.getJuiceSSHHostUUID();
if (hostUUID == null) {
Intent juiceSSHActivity = new Intent(context.getPackageManager().getLaunchIntentForPackage(PACKAGE_JUICESSH));
context.startActivity(juiceSSHActivity);
return true;
}

Intent juiceSSHActivity = new Intent(Intent.ACTION_VIEW);
juiceSSHActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
juiceSSHActivity.setData(Uri.parse("ssh://" + hostUUID));
context.startActivity(juiceSSHActivity);
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.net.Uri;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;

Expand Down Expand Up @@ -40,6 +39,9 @@ public class Preferences {
private static final String ICB_HOST_INTENT_URI = "IcbHostIntentUri";
private static final String ICB_HOST_NAME = "IcbHostName";
private static final String ICB_ENABLED = "IcbEnabled";
private static final String JUICESSH_HOST_INTENT_URI = "JuiceSSHHostIntentUri";
private static final String JUICESSH_HOST_NAME = "JuiceSSHHostName";
private static final String JUICESSH_ENABLED = "JuiceSSHEnabled";
private static final String THEME_DISABLED = "ThemeDisabled";
private static final String ACCOUNT_NAME = "AccountName";
private static final String CUSTOM_LIGHT_COLOR = "CustomLightColor";
Expand Down Expand Up @@ -193,7 +195,22 @@ public boolean getIcbEnabled() {
public String getIcbHostIntentUri() {
return sharedPreferences.getString(ICB_HOST_INTENT_URI, null);
}
public boolean setJuiceSSHHost(String hostName, String hostUri) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(JUICESSH_HOST_NAME, hostName);
editor.putString(JUICESSH_HOST_INTENT_URI, hostUri);
return editor.commit();
}

public String getJuiceSSHHostName() {
return sharedPreferences.getString(JUICESSH_HOST_NAME, null);
}
public boolean getJuiceSSHEnabled() {
return sharedPreferences.getBoolean(JUICESSH_ENABLED, true);
}
public String getJuiceSSHHostUUID() {
return sharedPreferences.getString(JUICESSH_HOST_INTENT_URI, null);
}
public boolean isThemeDisabled() {
return sharedPreferences.getBoolean(THEME_DISABLED, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
package fi.iki.murgo.irssinotifier;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
Expand All @@ -15,12 +19,20 @@
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;

import com.sonelli.juicessh.pluginlibrary.PluginContract;

import org.apache.http.auth.AuthenticationException;
import yuku.ambilwarna.AmbilWarnaDialog;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -152,6 +164,8 @@ public boolean onPreferenceClick(Preference preference) {

handleIcb();

handleJuiceSSH();

if (!LicenseHelper.isPlusVersion(this)) {
CheckBoxPreference usePullMechanismPref = (CheckBoxPreference)findPreference("UsePullMechanism");
usePullMechanismPref.setSummary(usePullMechanismPref.getSummary() + ". Only in Plus version.");
Expand Down Expand Up @@ -217,7 +231,7 @@ private void handleIcb() {
if (!IntentSniffer.isPackageAvailable(this, IrssiConnectbotLauncher.PACKAGE_IRSSICONNECTBOT)) {
PreferenceCategory icbCategory = (PreferenceCategory)findPreference("IcbCategory");
icbCategory.setEnabled(false);

showIcbIconPreference.setChecked(false);
showIcbIconPreference.setSummary("Install Irssi ConnectBot to show it in the action bar");
} else {
Expand All @@ -229,17 +243,17 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
return true;
}
});

Preference icbHostPref = findPreference("IcbHost");

Preferences prefs = new Preferences(this);
String hostName = prefs.getIcbHostName();

String summary = "Select which Irssi ConnectBot host to open when pressing the ICB icon";
if (hostName != null)
summary += ". Currently selected host: " + hostName;
icbHostPref.setSummary(summary);

icbHostPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Intent i = new Intent("android.intent.action.PICK");
Expand All @@ -251,6 +265,95 @@ public boolean onPreferenceClick(Preference preference) {
}
}

private void handleJuiceSSH() {
CheckBoxPreference showJuiceSSHIconPreference = (CheckBoxPreference)findPreference("JuiceSSHEnabled");
if (!IntentSniffer.isPackageAvailable(this, JuiceSSHLauncher.PACKAGE_JUICESSH)) {
PreferenceCategory juiceSSHCategory = (PreferenceCategory)findPreference("JuiceSSHCategory");
juiceSSHCategory.setEnabled(false);

showJuiceSSHIconPreference.setChecked(false);
showJuiceSSHIconPreference.setSummary("Install JuiceSSH to show it in the action bar");
} else {
showJuiceSSHIconPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
IrssiNotifierActivity.refreshIsNeeded();

return true;
}
});

Preference juiceSSHHostPref = findPreference("JuiceSSHHost");

final Preferences prefs = new Preferences(this);
String hostName = prefs.getJuiceSSHHostName();

String summary = "Select which JuiceSSH host to open when pressing the JuiceSSH icon";
if (hostName != null)
summary += ". Currently selected host: " + hostName;
juiceSSHHostPref.setSummary(summary);

final Activity context = this;
juiceSSHHostPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(final Preference preference) {
if (ContextCompat.checkSelfPermission(context, PluginContract.Connections.PERMISSION_READ)
!= PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(context,
new String[]{PluginContract.Connections.PERMISSION_READ},
0);
} else {
Cursor cursor = getContentResolver().query(
PluginContract.Connections.CONTENT_URI,
PluginContract.Connections.PROJECTION,
null,
null,
PluginContract.Connections.SORT_ORDER_DEFAULT
);

final ArrayList<String> allHostNames = new ArrayList<String>();
final ArrayList<String> allHostUUIDs = new ArrayList<String>();

List<String> connectionTypes = Arrays.asList(
"ssh",
"mosh",
"local",
"telnet"
);

while (cursor.moveToNext()) {

String hostname;
hostname = String.format(
"%s://%s:%s (%s)",
connectionTypes.get(cursor.getInt(cursor.getColumnIndex(PluginContract.Connections.COLUMN_TYPE))),
cursor.getString(cursor.getColumnIndex(PluginContract.Connections.COLUMN_ADDRESS)),
cursor.getString(cursor.getColumnIndex(PluginContract.Connections.COLUMN_PORT)),
cursor.getString(cursor.getColumnIndex(PluginContract.Connections.COLUMN_NICKNAME))
);

allHostNames.add(hostname);
allHostUUIDs.add(cursor.getString(cursor.getColumnIndex(PluginContract.Connections.COLUMN_ID)));
}
cursor.close();

AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Select JuiceSSH host");
builder.setItems(allHostNames.toArray(new String[allHostNames.size()]), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
prefs.setJuiceSSHHost(allHostNames.get(which), allHostUUIDs.get(which));
handleJuiceSSH();
}
});
builder.show();
}

return true;
}
});
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Expand Down
Binary file added Android/mobile/src/main/res/drawable/juicessh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 15 additions & 9 deletions Android/mobile/src/main/res/menu/mainmenu.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/menu_irssi_connectbot"
android:icon="@drawable/irssi_connectbot"
android:showAsAction="ifRoom|withText"
android:title="Launch Irssi ConnectBot"/>
android:title="Launch Irssi ConnectBot"
app:showAsAction="ifRoom|withText" />
<item
android:id="@+id/menu_juicessh"
android:icon="@drawable/juicessh"
android:title="Launch JuiceSSH"
app:showAsAction="ifRoom|withText" />
<item
android:id="@+id/menu_settings"
android:icon="@drawable/ic_menu_preferences"
android:showAsAction="ifRoom|withText"
android:title="Settings"/>
android:title="Settings"
app:showAsAction="ifRoom|withText" />
<item
android:id="@+id/menu_clear_channel"
android:icon="@drawable/ic_menu_close_clear_cancel"
android:showAsAction="never|withText"
android:title="Clear channel messages"/>
android:title="Clear channel messages"
app:showAsAction="never|withText" />
<item
android:id="@+id/menu_remove_all_channels"
android:icon="@drawable/ic_menu_close_clear_cancel"
android:showAsAction="never|withText"
android:title="Remove all channels"/>
android:title="Remove all channels"
app:showAsAction="never|withText" />

</menu>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions Android/mobile/src/main/res/xml/preference_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@
android:dependency="IcbEnabled" />
</PreferenceCategory>

<PreferenceCategory android:title="JuiceSSH integration" android:key="JuiceSSHCategory" >
<CheckBoxPreference
android:key="JuiceSSHEnabled"
android:defaultValue="true"
android:title="Show JuiceSSH icon"
android:summary="Show JuiceSSH icon in the action bar" />
<Preference
android:key="JuiceSSHHost"
android:title="Select JuiceSSH host"
android:summary=""
android:dependency="JuiceSSHEnabled" />
</PreferenceCategory>


<PreferenceCategory android:title="Misc" >
<Preference
android:key="channels"
Expand Down