Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
feat: Converted three util classes to Kotlin (#2399)
Browse files Browse the repository at this point in the history
* converted three util classes to kotlin

* converted util classes to kotlin

* format AuthUtil

* fixed authorisation to be nullable
  • Loading branch information
sriramr98 authored and iamareebjamal committed Mar 27, 2018
1 parent e2c3001 commit 6c7560f
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 296 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.fossasia.openevent.common

object ConstantStrings {

const val TOKEN = "token"

const val USER_EMAIL = "user_email"

const val USER_FIRST_NAME = "user_first_name"

const val USER_LAST_NAME = "user_last_name"

const val TRACK = "TRACK"

const val TRACK_ID = "TRACK_ID"

const val SESSION = "SESSION"

const val SESSION_TIMING = "SESSION_TIMING"

const val EMAIL = "EMAIL"

const val APP_NAME = "APP_NAME"

const val IS_AUTH_ENABLED = "is_auth_enabled"

const val EVENT_ID = "eventId"

const val ORG_DESCRIPTION = "organizer_description"

const val TIMEZONE = "timezone"

const val BASE_API_URL = "BASE_API_URL"

const val ID = "ID"

const val YOUTUBE = "youtu.be"

const val YOUTUBE_URI_1 = "http://img.youtube.com/vi/"

const val YOUTUBE_URI_2 = "/0.jpg"

const val EVENT_DAY = "EVENT_DAY"

const val SPEAKERS = "speakers"

const val SESSIONS = "sessions"

const val TRACKS = "tracks"

const val SESSION_TYPES = "session_types"

const val FEED = "feed"

const val VERSION = "version"

const val EventDates = "eventDates"

const val MICROLOCATIONS = "microlocations"

const val SPONSORS = "sponsors"

const val EVENT = "event"

const val DATABASE_RECORDS_EXIST = "database_records_exist"

const val IS_DOWNLOAD_DONE = "isDownloadDone"

const val IS_MAP_FRAGMENT_FROM_MAIN_ACTIVITY = "isMapFragmenFromMainActivity"

const val LOCATION_NAME = "locationName"

const val SESSION_MAP_ID = "sessionMapId"

const val IMAGE_ZOOM_KEY = "imageZoom"

//Sort order

const val PREF_SORT_SCHEDULE = "schedule_sort_type"

const val PREF_SORT_SPEAKER = "speaker_sort_type"

const val PREF_SORT_ORDER = "sort_order"

const val FACEBOOK_PAGE_ID = "pageId"

const val FACEBOOK_PAGE_NAME = "fbPageName"

const val TWITTER_PAGE_NAME = "twitterPageName"

const val FACEBOOK_COMMENTS = "comments"

//Social link names

const val SOCIAL_LINK_GITHUB = "GitHub"

const val SOCIAL_LINK_TWITTER = "Twitter"

const val SOCIAL_LINK_FACEBOOK = "Facebook"

const val SOCIAL_LINK_LINKEDIN = "LinkedIn"

const val SOCIAL_LINK_YOUTUBE = "YouTube"

const val SOCIAL_LINK_GOOGLE = "Google"
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.fossasia.openevent.common.notification

import android.app.AlarmManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent

import org.fossasia.openevent.common.ConstantStrings
import org.fossasia.openevent.common.date.DateConverter
import org.fossasia.openevent.data.Session
import org.fossasia.openevent.common.utils.SharedPreferencesUtil
import org.threeten.bp.ZonedDateTime

import io.reactivex.Completable
import timber.log.Timber

object NotificationUtil {

private fun onSuccess(session: Session) {
Timber.d("Created notification for Session ${session.id} ${session.title} at time ${session.startsAt}")
}

private fun onError(throwable: Throwable, session: Session) {
Timber.e(throwable)
Timber.e("Error creating Date for Session ${session.id} ${session.title} at time ${session.startsAt}")
}

@JvmStatic
fun createNotification(session: Session, context: Context): Completable {
return Completable.fromAction {
val zonedDateTime = DateConverter.getDate(session.startsAt)

val prefResult = Integer.parseInt(SharedPreferencesUtil.getString("notification", "10 mins")?.substring(0, 2)?.trim { it <= ' ' })
when (prefResult) {
1 -> zonedDateTime.minusHours(-1)
12 -> zonedDateTime.minusHours(12)
else -> zonedDateTime.minusMinutes(10)
}
// Checking if the event time is after the current time
if (zonedDateTime.isAfter(ZonedDateTime.now())) {
val myIntent = Intent(context, NotificationAlarmReceiver::class.java)
myIntent.putExtra(ConstantStrings.SESSION, session.id)
val pendingIntent = PendingIntent.getBroadcast(context, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT)

val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
alarmManager.set(AlarmManager.RTC, zonedDateTime.toInstant().toEpochMilli(), pendingIntent)
} else {
Timber.d("Session is finished. Skipping showing notification")
}
}.doOnComplete { onSuccess(session) }.doOnError { throwable -> onError(throwable, session) }
}
}
Loading

0 comments on commit 6c7560f

Please sign in to comment.