|
|
@@ -1,4 +1,4 @@
|
|
|
-package me.vadik.knigopis
|
|
|
+package me.vadik.knigopis.feature
|
|
|
|
|
|
import android.Manifest.permission.READ_PHONE_STATE
|
|
|
import android.content.Intent
|
|
|
@@ -21,26 +21,31 @@ import kotlinx.android.synthetic.main.activity_main.*
|
|
|
import kotlinx.android.synthetic.main.books_page.*
|
|
|
import kotlinx.android.synthetic.main.notes_page.*
|
|
|
import kotlinx.android.synthetic.main.users_page.*
|
|
|
-import me.vadik.knigopis.adapters.BooksAdapter
|
|
|
-import me.vadik.knigopis.adapters.notes.NotesAdapter
|
|
|
-import me.vadik.knigopis.adapters.users.UsersAdapter
|
|
|
-import me.vadik.knigopis.api.BookCoverSearch
|
|
|
-import me.vadik.knigopis.api.Endpoint
|
|
|
-import me.vadik.knigopis.auth.KAuth
|
|
|
-import me.vadik.knigopis.common.HeaderItemDecoration
|
|
|
-import me.vadik.knigopis.common.ResourceProvider
|
|
|
-import me.vadik.knigopis.common.StickyHeaderInterface
|
|
|
-import me.vadik.knigopis.data.*
|
|
|
-import me.vadik.knigopis.dialog.DialogFactory
|
|
|
-import me.vadik.knigopis.model.*
|
|
|
-import me.vadik.knigopis.model.CurrentTab.*
|
|
|
-import me.vadik.knigopis.model.note.Note
|
|
|
-import me.vadik.knigopis.model.subscription.Subscription
|
|
|
-import me.vadik.knigopis.profile.createProfileIntent
|
|
|
-import me.vadik.knigopis.user.createUserIntent
|
|
|
-import me.vadik.knigopis.utils.showNow
|
|
|
-import me.vadik.knigopis.utils.startActivityOrNull
|
|
|
-import me.vadik.knigopis.utils.toast
|
|
|
+import me.vadik.knigopis.*
|
|
|
+import me.vadik.knigopis.common.*
|
|
|
+import me.vadik.knigopis.feature.books.BooksAdapter
|
|
|
+import me.vadik.knigopis.feature.notes.NotesAdapter
|
|
|
+import me.vadik.knigopis.feature.users.UsersAdapter
|
|
|
+import me.vadik.knigopis.repository.api.BookCoverSearch
|
|
|
+import me.vadik.knigopis.repository.api.Endpoint
|
|
|
+import me.vadik.knigopis.repository.KAuth
|
|
|
+import me.vadik.knigopis.feature.book.createEditBookIntent
|
|
|
+import me.vadik.knigopis.feature.book.createNewBookIntent
|
|
|
+import me.vadik.knigopis.repository.cache.AvatarCache
|
|
|
+import me.vadik.knigopis.repository.cache.AvatarCacheImpl
|
|
|
+import me.vadik.knigopis.common.view.header.HeaderItemDecoration
|
|
|
+import me.vadik.knigopis.common.view.header.StickyHeaderInterface
|
|
|
+import me.vadik.knigopis.repository.*
|
|
|
+import me.vadik.knigopis.common.view.dialog.DialogFactory
|
|
|
+import me.vadik.knigopis.repository.model.*
|
|
|
+import me.vadik.knigopis.repository.model.CurrentTab.*
|
|
|
+import me.vadik.knigopis.repository.model.note.Note
|
|
|
+import me.vadik.knigopis.repository.model.subscription.Subscription
|
|
|
+import me.vadik.knigopis.feature.profile.createProfileIntent
|
|
|
+import me.vadik.knigopis.feature.user.createUserIntent
|
|
|
+import me.vadik.knigopis.common.extensions.showNow
|
|
|
+import me.vadik.knigopis.common.extensions.startActivityOrNull
|
|
|
+import me.vadik.knigopis.common.extensions.toast
|
|
|
import org.koin.android.ext.android.inject
|
|
|
import retrofit2.HttpException
|
|
|
|
|
|
@@ -140,7 +145,9 @@ class MainActivity : AppCompatActivity(), Router {
|
|
|
initNavigationView()
|
|
|
initToolbar(toolbar)
|
|
|
addBookButton.setOnClickListener {
|
|
|
- startActivityForResult(createNewBookIntent(), BOOK_REQUEST_CODE)
|
|
|
+ startActivityForResult(createNewBookIntent(),
|
|
|
+ BOOK_REQUEST_CODE
|
|
|
+ )
|
|
|
}
|
|
|
booksRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
|
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
|
|
@@ -202,10 +209,14 @@ class MainActivity : AppCompatActivity(), Router {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- override fun openEditBookScreen(book: Book) {
|
|
|
+ override fun openBookScreen(book: Book) {
|
|
|
when (book) {
|
|
|
- is PlannedBook -> startActivityForResult(createEditBookIntent(book), BOOK_REQUEST_CODE)
|
|
|
- is FinishedBook -> startActivityForResult(createEditBookIntent(book), BOOK_REQUEST_CODE)
|
|
|
+ is PlannedBook -> startActivityForResult(createEditBookIntent(book),
|
|
|
+ BOOK_REQUEST_CODE
|
|
|
+ )
|
|
|
+ is FinishedBook -> startActivityForResult(createEditBookIntent(book),
|
|
|
+ BOOK_REQUEST_CODE
|
|
|
+ )
|
|
|
else -> throw UnsupportedOperationException()
|
|
|
}
|
|
|
}
|
|
|
@@ -214,7 +225,7 @@ class MainActivity : AppCompatActivity(), Router {
|
|
|
startActivity(createUserIntent(id, name, avatar))
|
|
|
}
|
|
|
|
|
|
- override fun openBrowser(uri: Uri) {
|
|
|
+ override fun openWebPage(uri: Uri) {
|
|
|
startActivityOrNull(Intent(ACTION_VIEW, uri)) ?: toast(R.string.users_info_no_browser)
|
|
|
}
|
|
|
|
|
|
@@ -291,7 +302,8 @@ class MainActivity : AppCompatActivity(), Router {
|
|
|
profileOption = toolbar.menu.findItem(R.id.option_profile)
|
|
|
val darkThemeOption = toolbar.menu.findItem(R.id.option_dark_theme)
|
|
|
darkThemeOption.isChecked = config.isDarkTheme
|
|
|
- darkThemeOption.isVisible = BuildConfig.DEBUG // todo: remove before release
|
|
|
+ darkThemeOption.isVisible =
|
|
|
+ BuildConfig.DEBUG // todo: remove before release
|
|
|
toolbar.setOnClickListener {
|
|
|
if (currentTab == HOME_TAB) {
|
|
|
config.sortingMode = if (config.sortingMode == 0) 1 else 0
|
|
|
@@ -308,7 +320,9 @@ class MainActivity : AppCompatActivity(), Router {
|
|
|
auth.logout()
|
|
|
refresh()
|
|
|
} else {
|
|
|
- startActivityForResult(auth.getTokenRequest(), ULOGIN_REQUEST_CODE)
|
|
|
+ startActivityForResult(auth.getTokenRequest(),
|
|
|
+ ULOGIN_REQUEST_CODE
|
|
|
+ )
|
|
|
}
|
|
|
refreshOptionsMenu()
|
|
|
}
|