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 MediaPlayer mediaPlayer;
private boolean leavingScreen = false;
private RenderScript renderScript;
private Vibrator vibrator;
private Handler handler;
@ -306,8 +305,6 @@ public class CallNotificationController extends BaseController {
protected void onViewBound(@NonNull View view) {
super.onViewBound(view);
renderScript = RenderScript.create(getActivity());
if (handler == null) {
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.NotificationUser
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.DoNotDisturbUtils.isDnDActive
import com.nextcloud.talk.utils.DoNotDisturbUtils.isInDoNotDisturbWithPriority
@ -124,15 +125,18 @@ class NotificationWorker(
context: Context,
workerParams: WorkerParameters
) : Worker(context, workerParams) {
@JvmField
@Inject
internal var appPreferences: AppPreferences? = null
var appPreferences: AppPreferences? = null
@JvmField
@Inject
internal var arbitraryStorageUtils: ArbitraryStorageUtils? =
null
var arbitraryStorageUtils: ArbitraryStorageUtils? = null
@JvmField
@Inject
internal var retrofit: Retrofit? = null
var retrofit: Retrofit? = null
@JvmField
@Inject
internal var okHttpClient: OkHttpClient? = null
var okHttpClient: OkHttpClient? = null
private var ncApi: NcApi? = null
private var decryptedPushMessage: DecryptedPushMessage? = null
private var context: Context? = null
@ -180,8 +184,7 @@ class NotificationWorker(
override fun onSubscribe(d: Disposable) {}
override fun onNext(roomOverall: RoomOverall) {
val conversation: Conversation =
roomOverall.getOcs()
.getData()
roomOverall.ocs.data
intent.putExtra(
KEY_ROOM,
Parcels.wrap(
@ -557,7 +560,7 @@ class NotificationWorker(
LoganSquare.parse<RingtoneSettings>(
ringtonePreferencesString, RingtoneSettings::class.java
)
ringtoneSettings.getRingtoneUri()
ringtoneSettings.ringtoneUri
} catch (exception: IOException) {
Uri.parse(
"android.resource://" + context!!.packageName +
@ -634,7 +637,7 @@ class NotificationWorker(
base64DecodedSignature,
base64DecodedSubject
)
if (signatureVerification!!.isSignatureValid()) {
if (signatureVerification!!.signatureValid) {
val cipher: Cipher = Cipher.getInstance("RSA/None/PKCS1Padding")
cipher.init(Cipher.DECRYPT_MODE, privateKey)
val decryptedSubject: ByteArray? = cipher.doFinal(base64DecodedSubject)
@ -644,21 +647,19 @@ class NotificationWorker(
DecryptedPushMessage::class.java
)
decryptedPushMessage!!.timestamp = System.currentTimeMillis()
if (decryptedPushMessage!!.isDelete) {
if (decryptedPushMessage!!.delete) {
cancelExistingNotificationWithId(
context,
signatureVerification!!.getUserEntity(), decryptedPushMessage!!.notificationId
signatureVerification!!.userEntity, decryptedPushMessage!!.notificationId
)
} else if (decryptedPushMessage!!.isDeleteAll) {
} else if (decryptedPushMessage!!.deleteAll) {
cancelAllNotificationsForAccount(
context,
signatureVerification!!.getUserEntity()
signatureVerification!!.userEntity
)
} else {
credentials = ApiUtils.getCredentials(
signatureVerification!!.getUserEntity().username,
signatureVerification!!.getUserEntity().token
)
credentials = signatureVerification!!.userEntity.getCredentials()
ncApi = retrofit!!.newBuilder()
.client(
okHttpClient!!.newBuilder().cookieJar(
@ -669,8 +670,7 @@ class NotificationWorker(
.create(
NcApi::class.java
)
val hasChatSupport = signatureVerification!!.getUserEntity()
.hasSpreedFeatureCapability("chat-v2")
val hasChatSupport = signatureVerification!!.userEntity.hasSpreedFeatureCapability("chat-v2")
val shouldShowNotification = decryptedPushMessage!!.app == "spreed"
if (shouldShowNotification) {
val intent: Intent
@ -687,7 +687,7 @@ class NotificationWorker(
)
}
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(
KEY_ROOM_ID,
decryptedPushMessage!!.id
@ -700,7 +700,7 @@ class NotificationWorker(
}
bundle.putParcelable(
KEY_USER_ENTITY,
signatureVerification!!.getUserEntity()
signatureVerification!!.userEntity
)
bundle.putBoolean(
KEY_FROM_NOTIFICATION_START_CALL,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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