Move packages to com.moez.QKSMS

This commit is contained in:
Moez Bhatti
2018-06-20 14:29:07 -04:00
parent d8141737b3
commit a5f518042e
268 changed files with 1101 additions and 1116 deletions
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.feature.blocked
import android.app.AlertDialog
import android.arch.lifecycle.ViewModelProvider
import android.arch.lifecycle.ViewModelProviders
import android.os.Bundle
import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkThemedActivity
import dagger.android.AndroidInjection
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.blocked_activity.*
import kotlinx.android.synthetic.main.settings_switch_widget.view.*
import javax.inject.Inject
class BlockedActivity : QkThemedActivity(), BlockedView {
@Inject lateinit var blockedAdapter: BlockedAdapter
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
override val siaClickedIntent by lazy { shouldIAnswer.clicks() }
override val unblockIntent by lazy { blockedAdapter.unblock }
override val confirmUnblockIntent: Subject<Unit> = PublishSubject.create()
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[BlockedViewModel::class.java] }
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.blocked_activity)
setTitle(R.string.blocked_title)
showBackButton(true)
viewModel.bindView(this)
blockedAdapter.emptyView = empty
conversations.adapter = blockedAdapter
}
override fun render(state: BlockedState) {
shouldIAnswer.checkbox.isChecked = state.siaEnabled
blockedAdapter.updateData(state.data)
}
override fun showUnblockDialog() {
AlertDialog.Builder(this)
.setTitle(R.string.blocked_unblock_dialog_title)
.setMessage(R.string.blocked_unblock_dialog_message)
.setPositiveButton(R.string.button_unblock, { _, _ -> confirmUnblockIntent.onNext(Unit) })
.setNegativeButton(R.string.button_cancel, null)
.show()
}
}
@@ -0,0 +1,17 @@
package com.moez.QKSMS.feature.blocked
import android.arch.lifecycle.ViewModel
import com.moez.QKSMS.injection.ViewModelKey
import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
@Module
class BlockedActivityModule {
@Provides
@IntoMap
@ViewModelKey(BlockedViewModel::class)
fun provideBlockedViewModel(viewModel: BlockedViewModel): ViewModel = viewModel
}
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.feature.blocked
import android.view.LayoutInflater
import android.view.ViewGroup
import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkRealmAdapter
import com.moez.QKSMS.common.base.QkViewHolder
import com.moez.QKSMS.model.Conversation
import io.reactivex.subjects.PublishSubject
import kotlinx.android.synthetic.main.blocked_list_item.view.*
import javax.inject.Inject
class BlockedAdapter @Inject constructor() : QkRealmAdapter<Conversation>() {
val unblock: PublishSubject<Long> = PublishSubject.create()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
return QkViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.blocked_list_item, parent, false))
}
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
val conversation = getItem(position)!!
val view = holder.itemView
view.setOnClickListener { unblock.onNext(conversation.id) }
view.avatars.contacts = conversation.recipients
view.title.text = conversation.getTitle()
}
}
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.feature.blocked
import com.moez.QKSMS.model.Conversation
import io.realm.RealmResults
data class BlockedState(
val siaEnabled: Boolean = false,
val data: RealmResults<Conversation>? = null
)
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.feature.blocked
import com.moez.QKSMS.common.base.QkView
import io.reactivex.Observable
interface BlockedView : QkView<BlockedState> {
val siaClickedIntent: Observable<*>
val unblockIntent: Observable<Long>
val confirmUnblockIntent: Observable<*>
fun showUnblockDialog()
}
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.feature.blocked
import android.content.Context
import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.base.QkViewModel
import com.moez.QKSMS.interactor.MarkUnblocked
import com.moez.QKSMS.repository.ConversationRepository
import com.moez.QKSMS.util.Preferences
import com.moez.QKSMS.util.tryOrNull
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.kotlin.autoDisposable
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.withLatestFrom
import javax.inject.Inject
class BlockedViewModel @Inject constructor(
private val context: Context,
private val conversationRepo: ConversationRepository,
private val markUnblocked: MarkUnblocked,
private val navigator: Navigator,
private val prefs: Preferences
) : QkViewModel<BlockedView, BlockedState>(BlockedState()) {
init {
newState { copy(data = conversationRepo.getBlockedConversations()) }
disposables += prefs.sia.asObservable()
.subscribe { enabled -> newState { copy(siaEnabled = enabled) } }
}
override fun bindView(view: BlockedView) {
super.bindView(view)
view.siaClickedIntent
.map {
tryOrNull { context.packageManager.getApplicationInfo("org.mistergroup.shouldianswerpersonal", 0).enabled }
?: tryOrNull { context.packageManager.getApplicationInfo("org.mistergroup.muzutozvednout", 0).enabled }
?: false
}
.doOnNext { installed -> if (!installed) navigator.showSia() }
.withLatestFrom(prefs.sia.asObservable(), { installed, enabled -> installed && !enabled })
.autoDisposable(view.scope())
.subscribe { shouldEnable -> prefs.sia.set(shouldEnable) }
// Show confirm unblock conversation dialog
view.unblockIntent
.autoDisposable(view.scope())
.subscribe { view.showUnblockDialog() }
// Unblock conversation
view.confirmUnblockIntent
.withLatestFrom(view.unblockIntent, { _, threadId -> threadId })
.autoDisposable(view.scope())
.subscribe { threadId -> markUnblocked.execute(listOf(threadId)) }
}
}