Commit 73a0137d authored by narinder Rana's avatar narinder Rana
Browse files

added update missing classes in conflict

parent e1500a7f
Pipeline #169439 failed with stage
in 33 seconds
......@@ -18,6 +18,7 @@
*/
package com.moez.QKSMS.util
import android.app.AlarmManager
import android.app.PendingIntent
import android.content.Context
......@@ -33,20 +34,99 @@ import javax.inject.Singleton
@Singleton
class NightModeManager @Inject constructor(
private val context: Context,
private val prefs: Preferences,
private val widgetManager: WidgetManager
private val context: Context,
private val prefs: Preferences,
private val widgetManager: WidgetManager
) {
fun updateCurrentTheme() {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
when (prefs.nightMode.get()) {
Preferences.NIGHT_MODE_SYSTEM -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
}
Preferences.NIGHT_MODE_OFF -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
Preferences.NIGHT_MODE_ON -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}
Preferences.NIGHT_MODE_AUTO -> {
val nightStartTime = getPreviousInstanceOfTime(prefs.nightStart.get())
val nightEndTime = getPreviousInstanceOfTime(prefs.nightEnd.get())
// If the last nightStart was more recent than the last nightEnd, then it's night time
val night = nightStartTime > nightEndTime
prefs.night.set(night)
AppCompatDelegate.setDefaultNightMode(when (night) {
true -> AppCompatDelegate.MODE_NIGHT_YES
false -> AppCompatDelegate.MODE_NIGHT_NO
})
widgetManager.updateTheme()
}
}
}
fun updateNightMode(mode: Int) {
prefs.nightMode.set(Preferences.NIGHT_MODE_SYSTEM)
prefs.night.set(false)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
prefs.nightMode.set(mode)
// If it's not on auto mode, set the appropriate night mode
if (mode != Preferences.NIGHT_MODE_AUTO) {
prefs.night.set(mode == Preferences.NIGHT_MODE_ON)
AppCompatDelegate.setDefaultNightMode(when (mode) {
Preferences.NIGHT_MODE_OFF -> AppCompatDelegate.MODE_NIGHT_NO
Preferences.NIGHT_MODE_ON -> AppCompatDelegate.MODE_NIGHT_YES
Preferences.NIGHT_MODE_SYSTEM -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
else -> AppCompatDelegate.MODE_NIGHT_NO
})
widgetManager.updateTheme()
}
updateAlarms()
}
fun setNightStart(hour: Int, minute: Int) {
prefs.nightStart.set("$hour:$minute")
updateAlarms()
}
fun setNightEnd(hour: Int, minute: Int) {
prefs.nightEnd.set("$hour:$minute")
updateAlarms()
}
private fun updateAlarms() {
val dayCalendar = createCalendar(prefs.nightEnd.get())
val day = Intent(context, NightModeReceiver::class.java)
val dayIntent = PendingIntent.getBroadcast(context, 0, day, 0)
val nightCalendar = createCalendar(prefs.nightStart.get())
val night = Intent(context, NightModeReceiver::class.java)
val nightIntent = PendingIntent.getBroadcast(context, 1, night, 0)
context.sendBroadcast(day)
context.sendBroadcast(night)
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
if (prefs.nightMode.get() == Preferences.NIGHT_MODE_AUTO) {
alarmManager.setInexactRepeating(
AlarmManager.RTC_WAKEUP,
dayCalendar.timeInMillis,
AlarmManager.INTERVAL_DAY,
dayIntent
)
alarmManager.setInexactRepeating(
AlarmManager.RTC_WAKEUP,
nightCalendar.timeInMillis,
AlarmManager.INTERVAL_DAY,
nightIntent
)
} else {
alarmManager.cancel(dayIntent)
alarmManager.cancel(nightIntent)
}
}
private fun createCalendar(time: String): Calendar {
......
......@@ -50,11 +50,11 @@ import javax.inject.Singleton
@Singleton
class Navigator @Inject constructor(
private val context: Context,
private val analyticsManager: AnalyticsManager,
private val notificationManager: NotificationManager,
private val billingManager: BillingManager,
private val permissions: PermissionManager
private val context: Context,
private val analyticsManager: AnalyticsManager,
private val billingManager: BillingManager,
private val notificationManager: NotificationManager,
private val permissions: PermissionManager
) {
private fun startActivity(intent: Intent) {
......@@ -141,9 +141,24 @@ class Navigator @Inject constructor(
startActivity(intent)
}
fun openUri(uri: Uri) {
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
fun showDeveloper() {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/moezbhatti"))
startActivityExternal(intent)
}
fun showSourceCode() {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/moezbhatti/qksms"))
startActivityExternal(intent)
}
fun showChangelog() {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/moezbhatti/qksms/releases"))
startActivityExternal(intent)
}
fun showLicense() {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/moezbhatti/qksms/blob/master/LICENSE"))
startActivityExternal(intent)
}
fun showBlockedConversations() {
......@@ -277,6 +292,7 @@ class Navigator @Inject constructor(
if (threadId != 0L) {
notificationManager.createNotificationChannel(threadId)
}
val channelId = notificationManager.buildNotificationChannelId(threadId)
val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_CHANNEL_ID, channelId)
......@@ -285,6 +301,4 @@ class Navigator @Inject constructor(
}
}
}
}
\ No newline at end of file
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
* Copyright (C) 2020 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
......@@ -16,129 +16,32 @@
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.common.util
package com.moez.QKSMS.manager
import android.app.Activity
import android.content.Context
import com.android.billingclient.api.BillingClient
import com.android.billingclient.api.BillingClient.BillingResponse
import com.android.billingclient.api.BillingClient.SkuType
import com.android.billingclient.api.BillingClientStateListener
import com.android.billingclient.api.BillingFlowParams
import com.android.billingclient.api.Purchase
import com.android.billingclient.api.PurchasesUpdatedListener
import com.android.billingclient.api.SkuDetails
import com.android.billingclient.api.SkuDetailsParams
import com.moez.QKSMS.BuildConfig
import com.moez.QKSMS.manager.AnalyticsManager
import io.reactivex.Flowable
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class BillingManager @Inject constructor(
context: Context,
private val analyticsManager: AnalyticsManager
) : PurchasesUpdatedListener {
interface BillingManager {
companion object {
const val SKU_PLUS = "remove_ads"
const val SKU_PLUS_DONATE = "qksms_plus_donate"
}
val products: Observable<List<SkuDetails>> = BehaviorSubject.create()
val upgradeStatus: Observable<Boolean>
private val skus = listOf(SKU_PLUS, SKU_PLUS_DONATE)
private val purchaseListObservable = BehaviorSubject.create<List<Purchase>>()
private val billingClient: BillingClient = BillingClient.newBuilder(context).setListener(this).build()
private var isServiceConnected = false
init {
startServiceConnection {
queryPurchases()
querySkuDetailsAsync()
}
upgradeStatus = when (BuildConfig.FLAVOR) {
"noAnalytics" -> BehaviorSubject.createDefault(true)
else -> purchaseListObservable
.map { purchases -> purchases.any { it.sku == SKU_PLUS } || purchases.any { it.sku == SKU_PLUS_DONATE } }
.doOnNext { upgraded -> analyticsManager.setUserProperty("Upgraded", upgraded) }
}
}
private fun queryPurchases() {
executeServiceRequest {
// Load the cached data
purchaseListObservable.onNext(billingClient.queryPurchases(SkuType.INAPP).purchasesList.orEmpty())
// On a fresh device, the purchase might not be cached, and so we'll need to force a refresh
billingClient.queryPurchaseHistoryAsync(SkuType.INAPP) { _, _ ->
purchaseListObservable.onNext(billingClient.queryPurchases(SkuType.INAPP).purchasesList.orEmpty())
}
}
}
data class Product(
val sku: String,
val price: String,
val priceCurrencyCode: String
)
val products: Observable<List<Product>>
val upgradeStatus: Observable<Boolean>
private fun startServiceConnection(onSuccess: () -> Unit) {
val listener = object : BillingClientStateListener {
override fun onBillingSetupFinished(@BillingResponse billingResponseCode: Int) {
if (billingResponseCode == BillingResponse.OK) {
isServiceConnected = true
onSuccess()
} else {
Timber.w("Billing response: $billingResponseCode")
purchaseListObservable.onNext(listOf())
}
}
override fun onBillingServiceDisconnected() {
isServiceConnected = false
}
}
Flowable.fromCallable { billingClient.startConnection(listener) }
.subscribeOn(Schedulers.io())
.subscribe()
}
private fun querySkuDetailsAsync() {
executeServiceRequest {
val subParams = SkuDetailsParams.newBuilder().setSkusList(skus).setType(BillingClient.SkuType.INAPP)
billingClient.querySkuDetailsAsync(subParams.build()) { responseCode, skuDetailsList ->
if (responseCode == BillingResponse.OK) {
(products as Subject).onNext(skuDetailsList)
}
}
}
}
fun initiatePurchaseFlow(activity: Activity, sku: String) {
executeServiceRequest {
val params = BillingFlowParams.newBuilder().setSku(sku).setType(SkuType.INAPP)
billingClient.launchBillingFlow(activity, params.build())
}
}
suspend fun checkForPurchases()
private fun executeServiceRequest(runnable: () -> Unit) {
when (isServiceConnected) {
true -> runnable()
false -> startServiceConnection(runnable)
}
}
suspend fun queryProducts()
override fun onPurchasesUpdated(resultCode: Int, purchases: List<Purchase>?) {
if (resultCode == BillingResponse.OK) {
purchaseListObservable.onNext(purchases.orEmpty())
}
}
suspend fun initiatePurchaseFlow(activity: Activity, sku: String)
}
}
\ No newline at end of file
......@@ -80,7 +80,6 @@ class AvatarView @JvmOverloads constructor(
super.onFinishInflate()
if (!isInEditMode) {
applyTheme(threadId)
updateView()
}
}
......
......@@ -37,7 +37,7 @@ class TightTextView @JvmOverloads constructor(
val maxLineWidth = (0 until layout.lineCount)
.map(layout::getLineWidth)
.max() ?: 0f
.maxOrNull() ?: 0f
val width = Math.ceil(maxLineWidth.toDouble()).toInt() + compoundPaddingLeft + compoundPaddingRight
if (width < measuredWidth) {
......
......@@ -63,7 +63,7 @@ class BackupPresenter @Inject constructor(
.distinctUntilChanged()
.switchMap { backupRepo.getBackups() }
.doOnNext { backups -> newState { copy(backups = backups) } }
.map { backups -> backups.map { it.date }.max() ?: 0L }
.map { backups -> backups.map { it.date }.maxOrNull() ?: 0L }
.map { lastBackup ->
when (lastBackup) {
0L -> context.getString(R.string.backup_never)
......
......@@ -28,13 +28,9 @@ import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.provider.ContactsContract
import android.provider.MediaStore
import android.text.format.DateFormat
import android.util.Log
import android.util.TypedValue
import android.view.ContextThemeWrapper
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AlertDialog
......@@ -75,7 +71,7 @@ import java.util.*
import javax.inject.Inject
import kotlin.collections.HashMap
class ComposeActivity : QkThemedActivity(), ComposeView {
class ComposeActivity(override val selectPreferredSIM: Observable<*>) : QkThemedActivity(), ComposeView {
companion object {
private const val SelectContactRequestCode = 0
......@@ -115,7 +111,6 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
override val inputContentIntent by lazy { message.inputContentSelected }
override val scheduleSelectedIntent: Subject<Long> = PublishSubject.create()
override val changeSimIntent by lazy { sim.clicks() }
override val selectPreferredSIM by lazy { viewSelectPreferredSim.clicks() }
override val scheduleCancelIntent by lazy { scheduledCancel.clicks() }
override val sendIntent by lazy { send.clicks() }
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
......@@ -249,7 +244,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
override fun clearSelection() = messageAdapter.clearSelection()
override fun showDetails(details: String) {
AlertDialog.Builder(this, R.style.customAlertDialog)
AlertDialog.Builder(this)
.setTitle(R.string.compose_details_title)
.setMessage(details)
.setCancelable(true)
......@@ -272,8 +267,8 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
override fun requestDatePicker() {
val calendar = Calendar.getInstance()
DatePickerDialog(this, R.style.customAlertDialog, DatePickerDialog.OnDateSetListener { _, year, month, day ->
TimePickerDialog(this, R.style.customAlertDialog, TimePickerDialog.OnTimeSetListener { _, hour, minute ->
DatePickerDialog(this, DatePickerDialog.OnDateSetListener { _, year, month, day ->
TimePickerDialog(this, TimePickerDialog.OnTimeSetListener { _, hour, minute ->
calendar.set(Calendar.YEAR, year)
calendar.set(Calendar.MONTH, month)
calendar.set(Calendar.DAY_OF_MONTH, day)
......@@ -349,7 +344,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
override fun showQksmsPlusSnackbar(message: Int) {
Snackbar.make(contentView, message, Snackbar.LENGTH_LONG).run {
setAction(R.string.button_more) { viewQksmsPlusIntent.onNext(Unit) }
setActionTextColor(getColor(R.color.tools_theme))
setActionTextColor(colors.theme().theme)
show()
}
}
......@@ -397,10 +392,10 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
super.onSaveInstanceState(outState)
}
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
cameraDestination = savedInstanceState?.getParcelable(CameraDestinationKey)
super.onRestoreInstanceState(savedInstanceState)
}
// override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
// cameraDestination = savedInstanceState?.getParcelable(CameraDestinationKey)
// super.onRestoreInstanceState(savedInstanceState)
// }
override fun onBackPressed() = backPressedIntent.onNext(Unit)
......
......@@ -20,17 +20,13 @@ package com.moez.QKSMS.feature.compose
import android.content.Context
import android.net.Uri
import android.os.Build
import android.os.Vibrator
import android.provider.ContactsContract
import android.telephony.SmsManager
import android.telephony.SmsMessage
import android.util.Log
import android.view.inputmethod.EditorInfo
import androidx.annotation.RequiresApi
import androidx.core.content.getSystemService
import com.moez.QKSMS.R
import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.base.QkViewModel
import com.moez.QKSMS.common.util.BillingManager
import com.moez.QKSMS.common.util.ClipboardUtils
import com.moez.QKSMS.common.util.MessageDetailsFormatter
import com.moez.QKSMS.common.util.extensions.makeToast
......@@ -78,29 +74,29 @@ import javax.inject.Inject
import javax.inject.Named
class ComposeViewModel @Inject constructor(
@Named("query") private val query: String,
@Named("threadId") private val threadId: Long,
@Named("addresses") private val addresses: List<String>,
@Named("text") private val sharedText: String,
@Named("attachments") private val sharedAttachments: Attachments,
private val contactRepo: ContactRepository,
private val context: Context,
private val activeConversationManager: ActiveConversationManager,
private val addScheduledMessage: AddScheduledMessage,
private val billingManager: BillingManager,
private val cancelMessage: CancelDelayedMessage,
private val conversationRepo: ConversationRepository,
private val deleteMessages: DeleteMessages,
private val markRead: MarkRead,
private val messageDetailsFormatter: MessageDetailsFormatter,
private val messageRepo: MessageRepository,
private val navigator: Navigator,
private val permissionManager: PermissionManager,
private val phoneNumberUtils: PhoneNumberUtils,
private val prefs: Preferences,
private val retrySending: RetrySending,
private val sendMessage: SendMessage,
private val subscriptionManager: SubscriptionManagerCompat
@Named("query") private val query: String,
@Named("threadId") private val threadId: Long,
@Named("addresses") private val addresses: List<String>,
@Named("text") private val sharedText: String,
@Named("attachments") private val sharedAttachments: Attachments,
private val contactRepo: ContactRepository,
private val context: Context,
private val activeConversationManager: ActiveConversationManager,
private val addScheduledMessage: AddScheduledMessage,
private val billingManager: BillingManager,
private val cancelMessage: CancelDelayedMessage,
private val conversationRepo: ConversationRepository,
private val deleteMessages: DeleteMessages,
private val markRead: MarkRead,
private val messageDetailsFormatter: MessageDetailsFormatter,
private val messageRepo: MessageRepository,
private val navigator: Navigator,
private val permissionManager: PermissionManager,
private val phoneNumberUtils: PhoneNumberUtils,
private val prefs: Preferences,
private val retrySending: RetrySending,
private val sendMessage: SendMessage,
private val subscriptionManager: SubscriptionManagerCompat
) : QkViewModel<ComposeView, ComposeState>(ComposeState(
editingMode = threadId == 0L && addresses.isEmpty(),
threadId = threadId,
......@@ -747,4 +743,4 @@ class ComposeViewModel @Inject constructor(
?.let { bytes -> String(bytes) }
}
}
\ No newline at end of file
}
......@@ -35,8 +35,8 @@ import androidx.annotation.RequiresApi
import com.moez.QKSMS.feature.compose.editing.DetailedChipView
class ComposeWindowCallback(
private val localCallback: Window.Callback,
private val activity: Activity
private val localCallback: Window.Callback,
private val activity: Activity
) : Window.Callback {
override fun dispatchKeyEvent(keyEvent: KeyEvent): Boolean {
......@@ -83,10 +83,14 @@ class ComposeWindowCallback(
return localCallback.onCreatePanelMenu(i, menu)
}
override fun onPreparePanel(i: Int, view: View, menu: Menu): Boolean {
override fun onPreparePanel(i: Int, view: View?, menu: Menu): Boolean {
return localCallback.onPreparePanel(i, view, menu)
}
// override fun onPreparePanel(i: Int, view: View, menu: Menu): Boolean {
// return localCallback.onPreparePanel(i, view, menu)
// }
override fun onMenuOpened(i: Int, menu: Menu): Boolean {
return localCallback.onMenuOpened(i, menu)
}
......@@ -144,4 +148,4 @@ class ComposeWindowCallback(
override fun onActionModeFinished(actionMode: ActionMode) {
localCallback.onActionModeFinished(actionMode)
}
}
}
\ No newline at end of file
......@@ -26,8 +26,6 @@ import android.text.Layout
import android.text.Spannable
import android.text.SpannableString
import android.text.style.StyleSpan
import android.util.TypedValue
import android.view.ContextThemeWrapper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -76,14 +74,14 @@ import javax.inject.Inject
import javax.inject.Provider
class MessagesAdapter @Inject constructor(
subscriptionManager: SubscriptionManagerCompat,
private val context: Context,
private val colors: Colors,
private val dateFormatter: DateFormatter,
private val partsAdapterProvider: Provider<PartsAdapter>,
private val phoneNumberUtils: PhoneNumberUtils,
private val prefs: Preferences,
private val textViewStyler: TextViewStyler
subscriptionManager: SubscriptionManagerCompat,
private val context: Context,
private val colors: Colors,
private val dateFormatter: DateFormatter,
private val partsAdapterProvider: Provider<PartsAdapter>,
private val phoneNumberUtils: PhoneNumberUtils,
private val prefs: Preferences,
private val textViewStyler: TextViewStyler
) : QkRealmAdapter<Message>() {
companion object {
......@@ -148,13 +146,10 @@ class MessagesAdapter @Inject constructor(