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

Commit

Permalink
Merge branch 'master' into javi-1159-apptentive
Browse files Browse the repository at this point in the history
  • Loading branch information
Javi Pacheco committed Dec 22, 2016
2 parents 49965af + 8419b4b commit ccc165b
Show file tree
Hide file tree
Showing 75 changed files with 1,401 additions and 304 deletions.
10 changes: 10 additions & 0 deletions modules/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@
</intent-filter>
</receiver>

<receiver
android:name="cards.nine.app.receivers.bluetooth.BluetoothReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
</intent-filter>
</receiver>

<service
android:name="com.google.android.gms.analytics.CampaignTrackingService" />

Expand Down Expand Up @@ -184,6 +193,7 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<!-- Normal Permissions -->

<!-- Dangerous Permissions - Need user approve -->
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.
30 changes: 30 additions & 0 deletions modules/app/src/main/res/layout/edit_moment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,36 @@

</LinearLayout>

<LinearLayout
android:id="@+id/edit_moment_bluetooth_root"
style="@style/EditMomentItem">

<LinearLayout
style="@style/EditMomentHeaderContent">

<cards.nine.app.ui.components.widgets.TintableImageView
android:id="@+id/edit_moment_icon_bluetooth"
style="@style/EditMomentHeaderIconBluetooth"/>

<TextView
android:id="@+id/edit_moment_name_bluetooth"
style="@style/EditMomentHeaderBluetoothName"/>

<cards.nine.app.ui.components.widgets.TintableImageView
android:id="@+id/edit_moment_add_bluetooth"
style="@style/EditMomentHeaderActionAdd"/>

</LinearLayout>

<ImageView
style="@style/ActionsLine"/>

<LinearLayout
android:id="@+id/edit_moment_bluetooth_content"
style="@style/EditMomentBodyContent"/>

</LinearLayout>

</LinearLayout>

</ScrollView>
7 changes: 7 additions & 0 deletions modules/app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,24 @@
<string name="linkCollection">Acceso Rápido a Colección</string>
<string name="hours">Horas</string>
<string name="wifi">Wifi</string>
<string name="bluetooth">Bluetooth</string>

<string name="noLinkCollectionToMoment">No vincular Colección a este Momento</string>

<string name="addHoursToEditMoment">Añade restricciones de tiempo a este Momento y será mostrado en 9Cards sólo esas horas</string>

<string name="addWifiToEditMoment">Añade tus Wifi a este Momento y lo mostraremos cuando estés conectado a uno de ellos</string>

<string name="addBluetoothToEditMoment">Añade tus disposivos Bluetooth a este Momento y lo mostraremos cuando estés conectado a uno de ellos</string><!-- Pending review language -->

<string name="linkCollectionMessage">Puedes seleccionar una Colección y acceder rápidamente a las aplicaciones, contactos y accesos directos de esta Colección desde una barra a la derecha de 9Cards. Sólo tienes que hacer clic en el fondo o un swipe desde el borde derecho del Launcher</string>

<string name="widgetsErrorMessage">Hemos tenido problemas cargando los widgets. Inténtalo más tarde</string>

<string name="wifiDisconnected">No hemos encontrado wifis. Si tu no tienes conectada la Red Wifi, tu deberías hacerlo</string><!-- Pending review language -->

<string name="bluetoothDisconnected">No hemos encontrado Bluetooth emparejados. Si tu no tienes conectado el Bluetooth, tu deberías hacerlo</string><!-- Pending review language -->

<!-- Collections -->

<string name="createNewCollection">Crear nueva Colección</string>
Expand Down
1 change: 1 addition & 0 deletions modules/app/src/main/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<string name="icons_apps_folder">icons_apps</string>
<string name="shared_preferences_key">ninecards-shared-preferences</string>
<string name="user_id_key">ninecards-user-id</string>
<string name="bluetooth_key">bluetooth-devices</string>

<string name="shared_collection_url">http://nine.cards/collections/id/%1$s</string>

Expand Down
7 changes: 7 additions & 0 deletions modules/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,24 @@
<string name="linkCollection">Quick Access to Collection</string>
<string name="hours">Hours</string>
<string name="wifi">WiFi</string>
<string name="bluetooth">Bluetooth</string>

<string name="noLinkCollectionToMoment">No link collection to this Moment</string>

<string name="addHoursToEditMoment">Add time constraints to this Moment so it shows up in your launcher when you need it. </string>

<string name="addWifiToEditMoment">Add WiFi constraints to this Moment and it\'ll show when you are connected.</string>

<string name="addBluetoothToEditMoment">Add Bluetooth constraints to this Moment and it\'ll show when you are connected.</string><!-- Pending review language -->

<string name="linkCollectionMessage">You can select a collection and have quick access to the apps, contacts and shortcuts inside of this collection from the right drawer in 9Cards. You only have to click the background or swipe from the right edge.</string>

<string name="widgetsErrorMessage">There was a problem loading the widgets. Please try again.</string>

<string name="wifiDisconnected">There aren\'t wifi. If you don\'t have connected your wifi network, you should connect it</string><!-- Pending review language -->

<string name="bluetoothDisconnected">There aren\'t Bluetooth Paired Devices. If you don\'t have connected your Bluetooth, you should connect it</string><!-- Pending review language -->

<!-- Collections -->

<string name="createNewCollection">Create new Collection</string>
Expand Down
8 changes: 8 additions & 0 deletions modules/app/src/main/res/values/styles_actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@
<item name="android:src">@drawable/icon_edit_moment_wifi</item>
</style>

<style name="EditMomentHeaderIconBluetooth" parent="EditMomentHeaderIcon">
<item name="android:src">@drawable/icon_edit_moment_bluetooth</item>
</style>

<style name="EditMomentHeaderName">
<item name="android:layout_width">0px</item>
<item name="android:layout_height">wrap_content</item>
Expand All @@ -388,6 +392,10 @@
<item name="android:text">@string/wifi</item>
</style>

<style name="EditMomentHeaderBluetoothName" parent="EditMomentHeaderName">
<item name="android:text">@string/bluetooth</item>
</style>

<style name="EditMomentHeaderAction">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package cards.nine.app.commons

import android.content.Context
import java.io.File

import android.content.{Context, SharedPreferences}
import cards.nine.commons.contexts.ContextSupport
import com.fortysevendeg.ninecardslauncher.R

trait ContextSupportPreferences { self: ContextSupport =>

override def getAppIconsDir =
override def getAppIconsDir: File =
context.getDir(getResources.getString(R.string.icons_apps_folder), Context.MODE_PRIVATE)

override def getSharedPreferences =
override def getSharedPreferences: SharedPreferences =
context.getSharedPreferences(
getResources.getString(R.string.shared_preferences_key),
Context.MODE_PRIVATE)
Expand All @@ -18,15 +20,43 @@ trait ContextSupportPreferences { self: ContextSupport =>
val key = getResources.getString(R.string.user_id_key)
val pref = getSharedPreferences
if (pref.contains(key)) {
Some(getSharedPreferences.getInt(key, 0))
Option(getSharedPreferences.getInt(key, 0))
} else {
None
}
}

override def setActiveUserId(id: Int): Unit = {
val editor = getSharedPreferences.edit()
editor.putInt(getResources.getString(R.string.user_id_key), id)
editor.apply()
}

override def addBluetoothDevice(device: String): Unit = {
import scala.collection.JavaConverters._
putBluetoothDevice((getBluetoothDevicesConnected + device).asJava)
}

override def removeBluetoothDevice(device: String): Unit = {
import scala.collection.JavaConverters._
putBluetoothDevice((getBluetoothDevicesConnected - device).asJava)
}

override def getBluetoothDevicesConnected: Set[String] = {
val key = getResources.getString(R.string.bluetooth_key)
val pref = getSharedPreferences
if (pref.contains(key)) {
import scala.collection.JavaConversions._
getSharedPreferences.getStringSet(key, new java.util.TreeSet[String]()).toSet
} else {
Set.empty
}
}

private[this] def putBluetoothDevice(devices: java.util.Set[String]): Unit = {
val editor = getSharedPreferences.edit()
editor.putStringSet(getResources.getString(R.string.bluetooth_key), devices)
editor.apply()
}

}
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
package cards.nine.app.commons

import java.io.File

import android.accounts.AccountManager
import android.app.{Activity, AlarmManager, Application}
import android.content.{Context, Intent}
import android.content.pm.PackageManager
import android.content.res.{AssetManager, Resources}
import android.content.{ContentResolver, Context, Intent}
import cards.nine.commons.contexts.{ActivityContextSupport, ContextSupport}
import macroid.{ActivityContextWrapper, ContextWrapper}

import scala.ref.WeakReference

trait ContextSupportImpl extends ContextSupport {

override def getContentResolver = context.getContentResolver
override def getContentResolver: ContentResolver = context.getContentResolver

override def getPackageManager = context.getPackageManager
override def getPackageManager: PackageManager = context.getPackageManager

override def getResources = context.getResources
override def getResources: Resources = context.getResources

override def getFilesDir = context.getFilesDir
override def getFilesDir: File = context.getFilesDir

override def getAssets = context.getAssets
override def getAssets: AssetManager = context.getAssets

override def getPackageName = context.getPackageName
override def getPackageName: String = context.getPackageName

override def getAccountManager: AccountManager = AccountManager.get(context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ trait AppNineCardsIntentConversions extends NineCardsIntentConversions {
collectionId = None,
timeslot = cloudStorageMoment.timeslot map toTimeSlot,
wifi = cloudStorageMoment.wifi,
bluetooth = cloudStorageMoment.bluetooth getOrElse Seq.empty,
headphone = cloudStorageMoment.headphones,
momentType = cloudStorageMoment.momentType,
widgets = cloudStorageMoment.widgets map toWidgetDataSeq)
Expand All @@ -186,11 +187,12 @@ trait AppNineCardsIntentConversions extends NineCardsIntentConversions {
collectionId = None,
timeslot = cloudStorageMoment.timeslot map toTimeSlot,
wifi = cloudStorageMoment.wifi,
bluetooth = cloudStorageMoment.bluetooth getOrElse Seq.empty,
headphone = cloudStorageMoment.headphones,
momentType = cloudStorageMoment.momentType,
widgets = cloudStorageMoment.widgets map toWidgetDataSeq)

def toWidgetDataSeq(widgets: Seq[CloudStorageWidget]) =
def toWidgetDataSeq(widgets: Seq[CloudStorageWidget]): Seq[WidgetData] =
widgets map toWidgetData

def toWidgetData(widget: CloudStorageWidget): WidgetData =
Expand Down
8 changes: 4 additions & 4 deletions modules/app/src/main/scala/cards/nine/app/di/Injector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import cards.nine.services.plus.impl.GooglePlusServicesImpl
import cards.nine.services.shortcuts.impl.ShortcutsServicesImpl
import cards.nine.services.track.impl.ConsoleTrackServices
import cards.nine.services.widgets.impl.WidgetsServicesImpl
import cards.nine.services.wifi.impl.WifiServicesImpl
import cards.nine.services.connectivity.impl.ConnectivityServicesImpl
import com.facebook.stetho.okhttp3.StethoInterceptor
import com.fortysevendeg.ninecardslauncher.R
import com.google.android.gms.analytics.GoogleAnalytics
Expand Down Expand Up @@ -175,7 +175,7 @@ class InjectorImpl(implicit contextSupport: ContextSupport) extends Injector {

private[this] lazy val callsServices = new CallsServicesImpl(contentResolverWrapper)

private[this] lazy val wifiServices = new WifiServicesImpl()
private[this] lazy val connectivityServices = new ConnectivityServicesImpl()

// Process

Expand All @@ -192,7 +192,7 @@ class InjectorImpl(implicit contextSupport: ContextSupport) extends Injector {
imageServices = imageServices,
widgetsServices = widgetsServices,
callsServices = callsServices,
wifiServices = wifiServices)
connectivityServices = connectivityServices)

private[this] lazy val nameCategories: Map[NineCardsCategory, String] =
(allCategories map { category =>
Expand All @@ -215,7 +215,7 @@ class InjectorImpl(implicit contextSupport: ContextSupport) extends Injector {

lazy val momentProcess = new MomentProcessImpl(
persistenceServices = persistenceServices,
wifiServices = wifiServices,
connectivityServices = connectivityServices,
awarenessServices = awarenessServices)

lazy val userProcess =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cards.nine.app.receivers.bluetooth

import cards.nine.app.ui.commons.action_filters.MomentBestAvailableActionFilter
import cards.nine.app.ui.commons.{BroadAction, Jobs}
import cards.nine.commons.services.TaskService
import cards.nine.commons.services.TaskService.TaskService
import cards.nine.commons.services.TaskService._
import macroid.ContextWrapper

class BluetoothJobs(implicit contextWrapper: ContextWrapper) extends Jobs {

def addBluetoothDevice(device: String): TaskService[Unit] =
for {
_ <- TaskService.right(contextSupport.addBluetoothDevice(device))
_ <- sendBroadCastTask(BroadAction(MomentBestAvailableActionFilter.action))
} yield ()

def removeBluetoothDevice(device: String): TaskService[Unit] =
for {
_ <- TaskService.right(contextSupport.removeBluetoothDevice(device))
_ <- sendBroadCastTask(BroadAction(MomentBestAvailableActionFilter.action))
} yield ()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cards.nine.app.receivers.bluetooth

import android.bluetooth.BluetoothDevice
import android.content.{BroadcastReceiver, Context, Intent}
import cards.nine.app.ui.commons.ops.TaskServiceOps._
import macroid.ContextWrapper

class BluetoothReceiver extends BroadcastReceiver {

override def onReceive(context: Context, intent: Intent): Unit = {

implicit val contextWrapper = ContextWrapper(context)

val jobs = new BluetoothJobs

(intent.getAction,
Option(intent.getParcelableExtra[BluetoothDevice](BluetoothDevice.EXTRA_DEVICE))) match {
case (action, Some(device: BluetoothDevice))
if action.equals(BluetoothDevice.ACTION_ACL_CONNECTED) =>
jobs.addBluetoothDevice(device.getName).resolveAsync()
case (action, Some(device: BluetoothDevice))
if action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED) =>
jobs.removeBluetoothDevice(device.getName).resolveAsync()
case _ =>
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ object AppLog {

val tag = "9cards"

def invalidConfigurationV2 = info("Invalid configuration for backend V2")
def invalidConfigurationV2: Unit = info("Invalid configuration for backend V2")

def info(message: String) = Log.i(tag, message)
def info(message: String): Unit = Log.i(tag, message)

def printErrorMessage(ex: Throwable, message: Option[String] = None) = {
def printErrorMessage(ex: Throwable, message: Option[String] = None): Unit = {
try {
val outputEx = Option(ex.getCause) getOrElse ex
Log.e(tag, message getOrElse errorMessage(outputEx), outputEx)
Crashlytics.logException(ex)
} catch { case _: Throwable => }
}

def printErrorTaskMessage(header: String, ex: Throwable) = {
def printErrorTaskMessage(header: String, ex: Throwable): Unit = {
try {
Log.e(tag, header)
printErrorMessage(ex, Some(errorMessage(ex)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class AddMomentJobs(actions: AddMomentUiActions)(implicit contextWrapper: Activi
collectionId = None,
timeslot = nineCardsMoment.toMomentTimeSlot,
wifi = Seq.empty,
bluetooth = Seq.empty,
headphone = false,
momentType = nineCardsMoment)
for {
Expand Down
Loading

0 comments on commit ccc165b

Please sign in to comment.