More Kotlin & Coil

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-10-26 22:52:32 +02:00
parent a0d932e946
commit e7790b38d1
8 changed files with 52 additions and 55 deletions

View File

@ -136,7 +136,6 @@ public class CallNotificationController extends BaseController {
private Conversation currentConversation; private Conversation currentConversation;
private MediaPlayer mediaPlayer; private MediaPlayer mediaPlayer;
private boolean leavingScreen = false; private boolean leavingScreen = false;
private RenderScript renderScript;
private Vibrator vibrator; private Vibrator vibrator;
private Handler handler; private Handler handler;
@ -306,8 +305,6 @@ public class CallNotificationController extends BaseController {
protected void onViewBound(@NonNull View view) { protected void onViewBound(@NonNull View view) {
super.onViewBound(view); super.onViewBound(view);
renderScript = RenderScript.create(getActivity());
if (handler == null) { if (handler == null) {
handler = new Handler(); handler = new Handler();
} }

View File

@ -77,6 +77,7 @@ import com.nextcloud.talk.models.json.notifications.NotificationOverall
import com.nextcloud.talk.models.json.push.DecryptedPushMessage import com.nextcloud.talk.models.json.push.DecryptedPushMessage
import com.nextcloud.talk.models.json.push.NotificationUser import com.nextcloud.talk.models.json.push.NotificationUser
import com.nextcloud.talk.newarch.utils.Images import com.nextcloud.talk.newarch.utils.Images
import com.nextcloud.talk.newarch.utils.getCredentials
import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DoNotDisturbUtils.isDnDActive import com.nextcloud.talk.utils.DoNotDisturbUtils.isDnDActive
import com.nextcloud.talk.utils.DoNotDisturbUtils.isInDoNotDisturbWithPriority import com.nextcloud.talk.utils.DoNotDisturbUtils.isInDoNotDisturbWithPriority
@ -124,15 +125,18 @@ class NotificationWorker(
context: Context, context: Context,
workerParams: WorkerParameters workerParams: WorkerParameters
) : Worker(context, workerParams) { ) : Worker(context, workerParams) {
@JvmField
@Inject @Inject
internal var appPreferences: AppPreferences? = null var appPreferences: AppPreferences? = null
@JvmField
@Inject @Inject
internal var arbitraryStorageUtils: ArbitraryStorageUtils? = var arbitraryStorageUtils: ArbitraryStorageUtils? = null
null @JvmField
@Inject @Inject
internal var retrofit: Retrofit? = null var retrofit: Retrofit? = null
@JvmField
@Inject @Inject
internal var okHttpClient: OkHttpClient? = null var okHttpClient: OkHttpClient? = null
private var ncApi: NcApi? = null private var ncApi: NcApi? = null
private var decryptedPushMessage: DecryptedPushMessage? = null private var decryptedPushMessage: DecryptedPushMessage? = null
private var context: Context? = null private var context: Context? = null
@ -180,8 +184,7 @@ class NotificationWorker(
override fun onSubscribe(d: Disposable) {} override fun onSubscribe(d: Disposable) {}
override fun onNext(roomOverall: RoomOverall) { override fun onNext(roomOverall: RoomOverall) {
val conversation: Conversation = val conversation: Conversation =
roomOverall.getOcs() roomOverall.ocs.data
.getData()
intent.putExtra( intent.putExtra(
KEY_ROOM, KEY_ROOM,
Parcels.wrap( Parcels.wrap(
@ -557,7 +560,7 @@ class NotificationWorker(
LoganSquare.parse<RingtoneSettings>( LoganSquare.parse<RingtoneSettings>(
ringtonePreferencesString, RingtoneSettings::class.java ringtonePreferencesString, RingtoneSettings::class.java
) )
ringtoneSettings.getRingtoneUri() ringtoneSettings.ringtoneUri
} catch (exception: IOException) { } catch (exception: IOException) {
Uri.parse( Uri.parse(
"android.resource://" + context!!.packageName + "android.resource://" + context!!.packageName +
@ -634,7 +637,7 @@ class NotificationWorker(
base64DecodedSignature, base64DecodedSignature,
base64DecodedSubject base64DecodedSubject
) )
if (signatureVerification!!.isSignatureValid()) { if (signatureVerification!!.signatureValid) {
val cipher: Cipher = Cipher.getInstance("RSA/None/PKCS1Padding") val cipher: Cipher = Cipher.getInstance("RSA/None/PKCS1Padding")
cipher.init(Cipher.DECRYPT_MODE, privateKey) cipher.init(Cipher.DECRYPT_MODE, privateKey)
val decryptedSubject: ByteArray? = cipher.doFinal(base64DecodedSubject) val decryptedSubject: ByteArray? = cipher.doFinal(base64DecodedSubject)
@ -644,21 +647,19 @@ class NotificationWorker(
DecryptedPushMessage::class.java DecryptedPushMessage::class.java
) )
decryptedPushMessage!!.timestamp = System.currentTimeMillis() decryptedPushMessage!!.timestamp = System.currentTimeMillis()
if (decryptedPushMessage!!.isDelete) { if (decryptedPushMessage!!.delete) {
cancelExistingNotificationWithId( cancelExistingNotificationWithId(
context, context,
signatureVerification!!.getUserEntity(), decryptedPushMessage!!.notificationId signatureVerification!!.userEntity, decryptedPushMessage!!.notificationId
) )
} else if (decryptedPushMessage!!.isDeleteAll) { } else if (decryptedPushMessage!!.deleteAll) {
cancelAllNotificationsForAccount( cancelAllNotificationsForAccount(
context, context,
signatureVerification!!.getUserEntity() signatureVerification!!.userEntity
) )
} else { } else {
credentials = ApiUtils.getCredentials( credentials = signatureVerification!!.userEntity.getCredentials()
signatureVerification!!.getUserEntity().username,
signatureVerification!!.getUserEntity().token
)
ncApi = retrofit!!.newBuilder() ncApi = retrofit!!.newBuilder()
.client( .client(
okHttpClient!!.newBuilder().cookieJar( okHttpClient!!.newBuilder().cookieJar(
@ -669,8 +670,7 @@ class NotificationWorker(
.create( .create(
NcApi::class.java NcApi::class.java
) )
val hasChatSupport = signatureVerification!!.getUserEntity() val hasChatSupport = signatureVerification!!.userEntity.hasSpreedFeatureCapability("chat-v2")
.hasSpreedFeatureCapability("chat-v2")
val shouldShowNotification = decryptedPushMessage!!.app == "spreed" val shouldShowNotification = decryptedPushMessage!!.app == "spreed"
if (shouldShowNotification) { if (shouldShowNotification) {
val intent: Intent val intent: Intent
@ -687,7 +687,7 @@ class NotificationWorker(
) )
} }
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
if (!signatureVerification!!.getUserEntity().hasSpreedFeatureCapability("no-ping")) { if (!signatureVerification!!.userEntity.hasSpreedFeatureCapability("no-ping")) {
bundle.putString( bundle.putString(
KEY_ROOM_ID, KEY_ROOM_ID,
decryptedPushMessage!!.id decryptedPushMessage!!.id
@ -700,7 +700,7 @@ class NotificationWorker(
} }
bundle.putParcelable( bundle.putParcelable(
KEY_USER_ENTITY, KEY_USER_ENTITY,
signatureVerification!!.getUserEntity() signatureVerification!!.userEntity
) )
bundle.putBoolean( bundle.putBoolean(
KEY_FROM_NOTIFICATION_START_CALL, KEY_FROM_NOTIFICATION_START_CALL,

View File

@ -27,6 +27,6 @@ import org.parceler.Parcel;
@Data @Data
@Parcel @Parcel
public class SignatureVerification { public class SignatureVerification {
boolean signatureValid; public boolean signatureValid;
UserEntity userEntity; public UserEntity userEntity;
} }

View File

@ -36,31 +36,31 @@ public class Notification {
@JsonField(name = "icon") @JsonField(name = "icon")
public String icon; public String icon;
@JsonField(name = "notification_id") @JsonField(name = "notification_id")
int notificationId; public int notificationId;
@JsonField(name = "app") @JsonField(name = "app")
String app; public String app;
@JsonField(name = "user") @JsonField(name = "user")
String user; public String user;
@JsonField(name = "datetime", typeConverter = LoganSquareJodaTimeConverter.class) @JsonField(name = "datetime", typeConverter = LoganSquareJodaTimeConverter.class)
DateTime datetime; public DateTime datetime;
@JsonField(name = "object_type") @JsonField(name = "object_type")
String objectType; public String objectType;
@JsonField(name = "object_id") @JsonField(name = "object_id")
String objectId; public String objectId;
@JsonField(name = "subject") @JsonField(name = "subject")
String subject; public String subject;
@JsonField(name = "subjectRich") @JsonField(name = "subjectRich")
String subjectRich; public String subjectRich;
@JsonField(name = "subjectRichParameters") @JsonField(name = "subjectRichParameters")
HashMap<String, HashMap<String, String>> subjectRichParameters; public HashMap<String, HashMap<String, String>> subjectRichParameters;
@JsonField(name = "message") @JsonField(name = "message")
String message; public String message;
@JsonField(name = "messageRich") @JsonField(name = "messageRich")
String messageRich; public String messageRich;
@JsonField(name = "messageRichParameters") @JsonField(name = "messageRichParameters")
HashMap<String, HashMap<String, String>> messageRichParameters; public HashMap<String, HashMap<String, String>> messageRichParameters;
@JsonField(name = "link") @JsonField(name = "link")
String link; public String link;
@JsonField(name = "actions") @JsonField(name = "actions")
List<NotificationAction> actions; public List<NotificationAction> actions;
} }

View File

@ -31,5 +31,5 @@ import org.parceler.Parcel;
@JsonObject @JsonObject
public class NotificationOCS extends GenericOCS { public class NotificationOCS extends GenericOCS {
@JsonField(name = "data") @JsonField(name = "data")
Notification notification; public Notification notification;
} }

View File

@ -28,5 +28,5 @@ import lombok.Data;
@JsonObject @JsonObject
public class NotificationOverall { public class NotificationOverall {
@JsonField(name = "ocs") @JsonField(name = "ocs")
NotificationOCS ocs; public NotificationOCS ocs;
} }

View File

@ -31,32 +31,32 @@ import org.parceler.Parcel;
@JsonObject @JsonObject
public class DecryptedPushMessage { public class DecryptedPushMessage {
@JsonField(name = "app") @JsonField(name = "app")
String app; public String app;
@JsonField(name = "type") @JsonField(name = "type")
String type; public String type;
@JsonField(name = "subject") @JsonField(name = "subject")
String subject; public String subject;
@JsonField(name = "id") @JsonField(name = "id")
String id; public String id;
@JsonField(name = "nid") @JsonField(name = "nid")
long notificationId; public long notificationId;
@JsonField(name = "delete") @JsonField(name = "delete")
boolean delete; public boolean delete;
@JsonField(name = "delete-all") @JsonField(name = "delete-all")
boolean deleteAll; public boolean deleteAll;
@JsonIgnore @JsonIgnore
NotificationUser notificationUser; public NotificationUser notificationUser;
@JsonIgnore @JsonIgnore
String text; public String text;
@JsonIgnore @JsonIgnore
long timestamp; public long timestamp;
} }

View File

@ -30,11 +30,11 @@ import org.parceler.Parcel;
@JsonObject @JsonObject
public class NotificationUser { public class NotificationUser {
@JsonField(name = "type") @JsonField(name = "type")
String type; public String type;
@JsonField(name = "id") @JsonField(name = "id")
String id; public String id;
@JsonField(name = "name") @JsonField(name = "name")
String name; public String name;
} }