Skip to content
This repository has been archived by the owner on Dec 8, 2019. It is now read-only.

Commit

Permalink
Merge branch 'internet-transport'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Jan 25, 2016
2 parents 28cb4f1 + ddb3d64 commit 6e12494
Show file tree
Hide file tree
Showing 68 changed files with 957 additions and 217 deletions.
10 changes: 6 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ buildscript {
dependencies {
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:multidex:1.0.1'
androidTestCompile 'com.android.support:multidex-instrumentation:1.0.1',
{ exclude module: 'multidex' }
compile 'org.scala-lang:scala-library:2.11.7'
compile 'com.mobsandgeeks:adapter-kit:0.5.3'
compile 'com.google.zxing:android-integration:3.2.1'
compile 'com.google.zxing:core:3.2.1'
compile project(path: ':core')
androidTestCompile 'com.android.support:multidex-instrumentation:1.0.1',
{ exclude module: 'multidex' }
}

// RtlHardcoded behaviour differs between target API versions. We only care about API 15.
Expand All @@ -37,8 +39,8 @@ android {
defaultConfig {
applicationId "com.nutomic.ensichat"
targetSdkVersion 23
versionCode 8
versionName "0.1.7"
versionCode project.properties.versionCode.toInteger()
versionName project.properties.versionName
multiDexEnabled true
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
Expand Down
6 changes: 4 additions & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<uses-feature android:name="android.hardware.bluetooth" android:required="true" />
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />

<application
android:name="android.support.multidex.MultiDexApplication"
android:name=".App"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@drawable/ic_launcher"
Expand Down
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.
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.
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.
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.
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.
44 changes: 29 additions & 15 deletions android/src/main/res/layout/fragment_identicon.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="25dp">
android:layout_height="match_parent">

<ImageView
android:id="@+id/identicon"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginBottom="25dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:padding="25dp">

<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/identicon"
android:layout_width="150dp"
android:layout_height="150dp"
android:scaleType="fitCenter" />

</LinearLayout>
<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp" />

<ImageView
android:id="@+id/qr_code"
android:layout_width="150dp"
android:layout_height="150dp"
android:scaleType="fitCenter" />

</LinearLayout>

</ScrollView>
17 changes: 17 additions & 0 deletions android/src/main/res/menu/connections.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/add_contact"
android:title="Add Contact"
android:icon="@drawable/ic_person_add_white_24dp"
app:showAsAction="ifRoom" />

<item
android:id="@+id/scan_qr"
android:title="Scan QR-Code"
android:icon="@drawable/ic_qrcode_white_24dp"
app:showAsAction="ifRoom" />

</menu>
9 changes: 8 additions & 1 deletion android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<!-- MainActivity -->

<!-- Toast shown if user denies request to enable bluetooth -->
<string name="bluetooth_required">Bluetooth is required for this app.</string>
<string name="toast_bluetooth_denied">Please enable Bluetooth to access the complete app functionality.</string>


<!-- ContactsFragment -->
Expand Down Expand Up @@ -60,6 +60,10 @@
<!-- Toast shown when clicking a user that is already a contact -->
<string name="contact_already_added">You have already added %1$s as a contact</string>

<string name="enter_id">Enter user ID</string>

<string name="invalid_address">Invalid address</string>


<!-- SettingsActivity -->

Expand Down Expand Up @@ -87,6 +91,9 @@
<!-- Preference title (debug only)-->
<string name="max_connections" translatable="false">Maximum Number of Connections</string>

<!-- Preference title -->
<string name="servers">Servers</string>

<!-- Preference title -->
<string name="report_issue">Report Issue</string>

Expand Down
4 changes: 4 additions & 0 deletions android/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
android:inputType="number"
android:numeric="integer" />

<EditTextPreference
android:title="@string/servers"
android:key="servers" />

<Preference
android:title="@string/report_issue"
android:summary="@string/report_issue_summary" >
Expand Down
15 changes: 15 additions & 0 deletions android/src/main/scala/com/nutomic/ensichat/App.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.nutomic.ensichat

import android.support.multidex.MultiDexApplication
import com.nutomic.ensichat.core.interfaces.Log
import com.nutomic.ensichat.util.{Logging, PRNGFixes}

class App extends MultiDexApplication {

override def onCreate(): Unit = {
super.onCreate()
Log.setLogInstance(new Logging())
PRNGFixes.apply()
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nutomic.ensichat.activities

import android.app.Activity
import android.app.AlertDialog.Builder
import android.content.DialogInterface.OnClickListener
import android.content._
Expand All @@ -9,7 +10,9 @@ import android.support.v4.content.LocalBroadcastManager
import android.view._
import android.widget.AdapterView.OnItemClickListener
import android.widget._
import com.google.zxing.integration.android.IntentIntegrator
import com.nutomic.ensichat.R
import com.nutomic.ensichat.core.Address
import com.nutomic.ensichat.service.CallbackHandler
import com.nutomic.ensichat.util.Database
import com.nutomic.ensichat.views.UsersAdapter
Expand All @@ -19,8 +22,6 @@ import com.nutomic.ensichat.views.UsersAdapter
*/
class ConnectionsActivity extends EnsichatActivity with OnItemClickListener {

private val Tag = "AddContactsActivity"

private lazy val database = new Database(this)

private lazy val adapter = new UsersAdapter(this)
Expand Down Expand Up @@ -57,22 +58,79 @@ class ConnectionsActivity extends EnsichatActivity with OnItemClickListener {
LocalBroadcastManager.getInstance(this).unregisterReceiver(onContactsUpdatedReceiver)
}

override def onCreateOptionsMenu(menu: Menu): Boolean = {
getMenuInflater.inflate(R.menu.connections, menu)
true
}

override def onOptionsItemSelected(item: MenuItem): Boolean = item.getItemId match {
case R.id.add_contact =>
val et = new EditText(this)
new Builder(this)
.setTitle(R.string.enter_id)
.setView(et)
.setPositiveButton(android.R.string.ok, new OnClickListener {
override def onClick(dialog: DialogInterface, which: Int): Unit = {
addContact(et.getText.toString)
}
})
.setNegativeButton(android.R.string.cancel, null)
.show()
true
case R.id.scan_qr =>
new IntentIntegrator(this).initiateScan
true
case android.R.id.home =>
NavUtils.navigateUpFromSameTask(this)
true
case _ =>
super.onOptionsItemSelected(item)
}

/**
* Initiates adding the device as contact if it hasn't been added yet.
*/
override def onItemClick(parent: AdapterView[_], view: View, position: Int, id: Long): Unit = {
val contact = adapter.getItem(position)
if (database.getContacts.contains(contact)) {
val text = getString(R.string.contact_already_added, contact.name)
override def onItemClick(parent: AdapterView[_], view: View, position: Int, id: Long): Unit =
addContact(adapter.getItem(position).address.toString)

/**
* Receives value of scanned QR code and sets it as device ID.
*/
override def onActivityResult(requestCode: Int, resultCode: Int, intent: Intent) {
val scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent)
if (scanResult != null && resultCode == Activity.RESULT_OK) {
addContact(scanResult.getContents)
}
}

/**
* Parses the address, and shows a dialog to add the user as a contact.
*
* Displays a warning toast if the address is invalid or if the user is already a contact.
*/
private def addContact(address: String): Unit = {
val parsedAddress =
try {
new Address(address)
} catch {
case e: IllegalArgumentException =>
Toast.makeText(this, R.string.invalid_address, Toast.LENGTH_LONG).show()
return
}

val user = service.get.getUser(parsedAddress)

if (database.getContacts.map(_.address).contains(user.address)) {
val text = getString(R.string.contact_already_added, user.name)
Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
return
}

new Builder(this)
.setMessage(getString(R.string.dialog_add_contact, contact.name))
.setMessage(getString(R.string.dialog_add_contact, user.name))
.setPositiveButton(android.R.string.yes, new OnClickListener {
override def onClick(dialog: DialogInterface, which: Int): Unit = {
database.addContact(contact)
database.addContact(user)
Toast.makeText(ConnectionsActivity.this, R.string.toast_contact_added, Toast.LENGTH_SHORT)
.show()
}
Expand All @@ -81,14 +139,6 @@ class ConnectionsActivity extends EnsichatActivity with OnItemClickListener {
.show()
}

override def onOptionsItemSelected(item: MenuItem): Boolean = item.getItemId match {
case android.R.id.home =>
NavUtils.navigateUpFromSameTask(this)
true
case _ =>
super.onOptionsItemSelected(item);
}

/**
* Fetches connections and displays them (excluding contacts).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import android.view.{KeyEvent, View}
import android.widget.TextView.OnEditorActionListener
import android.widget.{Button, EditText, TextView}
import com.nutomic.ensichat.R
import com.nutomic.ensichat.core.interfaces.Settings
import com.nutomic.ensichat.core.interfaces.Settings._
import com.nutomic.ensichat.core.interfaces.SettingsInterface
import com.nutomic.ensichat.core.interfaces.SettingsInterface._

/**
* Shown on first start, lets the user enter their name.
Expand Down Expand Up @@ -69,11 +69,12 @@ class FirstStartActivity extends AppCompatActivity with OnEditorActionListener w
preferences
.edit()
.putBoolean(KeyIsFirstStart, false)
.putString(Settings.KeyUserName, username.getText.toString.trim)
.putString(Settings.KeyUserStatus, Settings.DefaultUserStatus)
.putBoolean(Settings.KeyNotificationSoundsOn, DefaultNotificationSoundsOn)
.putString(Settings.KeyScanInterval, DefaultScanInterval.toString)
.putString(Settings.KeyMaxConnections, DefaultMaxConnections.toString)
.putString(KeyUserName, username.getText.toString.trim)
.putString(KeyUserStatus, SettingsInterface.DefaultUserStatus)
.putBoolean(KeyNotificationSoundsOn, DefaultNotificationSoundsOn)
.putString(KeyScanInterval, DefaultScanInterval.toString)
.putString(KeyMaxConnections, DefaultMaxConnections.toString)
.putString(KeyServers, DefaultServers.mkString(", "))
.apply()

startMainActivity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class MainActivity extends EnsichatActivity {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

if (getIntent.getAction == MainActivity.ActionRequestBluetooth) {
if (getIntent.getAction == MainActivity.ActionRequestBluetooth &&
Option(BluetoothAdapter.getDefaultAdapter).isDefined) {
val intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE)
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0)
startActivityForResult(intent, RequestSetDiscoverable)
Expand Down Expand Up @@ -89,8 +90,7 @@ class MainActivity extends EnsichatActivity {
requestCode match {
case RequestSetDiscoverable =>
if (resultCode == Activity.RESULT_CANCELED) {
Toast.makeText(this, R.string.bluetooth_required, Toast.LENGTH_LONG).show()
finish()
Toast.makeText(this, R.string.toast_bluetooth_denied, Toast.LENGTH_LONG).show()
}
}

Expand Down Expand Up @@ -120,7 +120,8 @@ class MainActivity extends EnsichatActivity {
currentChat = None
getSupportActionBar.setDisplayHomeAsUpEnabled(false)
setTitle(R.string.app_name)
}
} else
super.onBackPressed()
}

override def onOptionsItemSelected(item: MenuItem): Boolean = item.getItemId match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.util.Log
/**
* Attempts to connect to another device and calls [[onConnected]] on success.
*/
class ConnectThread(device: Device, onConnected: (Device, BluetoothSocket) => Unit) extends Thread {
class BluetoothConnectThread(device: Device, onConnected: (Device, BluetoothSocket) => Unit) extends Thread {

private val Tag = "ConnectThread"

Expand Down
Loading

0 comments on commit 6e12494

Please sign in to comment.