diff --git a/BibliotecaUFABC/.idea/dictionaries/Mauro.xml b/BibliotecaUFABC/.idea/dictionaries/mauro.xml similarity index 61% rename from BibliotecaUFABC/.idea/dictionaries/Mauro.xml rename to BibliotecaUFABC/.idea/dictionaries/mauro.xml index d69e99b..becf46b 100644 --- a/BibliotecaUFABC/.idea/dictionaries/Mauro.xml +++ b/BibliotecaUFABC/.idea/dictionaries/mauro.xml @@ -1,7 +1,10 @@ - andré + codigo + detalhe + obra + tipo \ No newline at end of file diff --git a/BibliotecaUFABC/app/build.gradle b/BibliotecaUFABC/app/build.gradle index 2f60164..128acf3 100644 --- a/BibliotecaUFABC/app/build.gradle +++ b/BibliotecaUFABC/app/build.gradle @@ -44,11 +44,13 @@ dependencies { implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.vectordrawable:vectordrawable:1.1.0' + implementation 'androidx.activity:activity-ktx:1.3.0-beta01' implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" implementation "androidx.navigation:navigation-ui-ktx:$nav_version" implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.preference:preference-ktx:1.1.1' implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation 'androidx.fragment:fragment-ktx:1.4.0-alpha02' implementation "androidx.concurrent:concurrent-futures-ktx:1.1.0" testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2' @@ -71,7 +73,7 @@ dependencies { } dependencies { - def work_version = '2.6.0-alpha02' + def work_version = '2.6.0-beta01' implementation "androidx.work:work-runtime-ktx:$work_version" androidTestImplementation "androidx.work:work-testing:$work_version" } diff --git a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/BookViewerActivity.kt b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/BookViewerActivity.kt index e666fba..b36097b 100644 --- a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/BookViewerActivity.kt +++ b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/BookViewerActivity.kt @@ -7,6 +7,7 @@ import android.os.Bundle import android.os.Handler import android.view.MenuItem import android.webkit.WebView +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AlertDialog import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider @@ -36,6 +37,25 @@ class BookViewerActivity : AppCompatActivity(), BookViewerFragment.ReservationEv private lateinit var messageViewModel: MessageViewModel private lateinit var bookViewerViewModel: BookViewerViewModel + val openLoginActivity = registerForActivityResult(ActivityResultContracts + .StartActivityForResult()){ result -> + if (result.resultCode == Activity.RESULT_OK && result.data != null){ + detailsWebClient?.resetCounters() + + bookViewerViewModel.setLoginRequest(true) + bookViewerViewModel.setReservationRequest(true) + + dataSource?.loadUrl(bookViewerViewModel.bookURL.value!!) + Snackbar.make(bookViewerParent, + getString(R.string.snack_message_connected, + result.data!!.getStringExtra(Constants.CONNECTED_STATUS_USER_NAME)), + Snackbar.LENGTH_LONG).show() + + loggedInAs.value = result.data!!.getStringExtra(Constants.CONNECTED_STATUS_USER_NAME) + } + else bookViewerViewModel.setLoginCancelled(true) + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_book_viewer) @@ -63,28 +83,6 @@ class BookViewerActivity : AppCompatActivity(), BookViewerFragment.ReservationEv } } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - - if (requestCode == Constants.ACTIVITY_LOGIN_REQUEST_CODE){ - if (resultCode == Activity.RESULT_OK && data != null){ - detailsWebClient?.resetCounters() - - bookViewerViewModel.setLoginRequest(true) - bookViewerViewModel.setReservationRequest(true) - - dataSource?.loadUrl(bookViewerViewModel.bookURL.value!!) - Snackbar.make(bookViewerParent, - getString(R.string.snack_message_connected, - data.getStringExtra(Constants.CONNECTED_STATUS_USER_NAME)), - Snackbar.LENGTH_LONG).show() - - loggedInAs.value = data.getStringExtra(Constants.CONNECTED_STATUS_USER_NAME) - } - else bookViewerViewModel.setLoginCancelled(true) - } - } - private fun initializeBookData(){ var hasData = true var bookData = intent.getStringExtra(Constants.BOOK_CODE) @@ -112,8 +110,7 @@ class BookViewerActivity : AppCompatActivity(), BookViewerFragment.ReservationEv commitAllowingStateLoss() } if (bookViewerViewModel.loginCancelled.value!!){ - startActivityForResult(Intent(this, LoginActivity::class.java), - Constants.ACTIVITY_LOGIN_REQUEST_CODE) + openLoginActivity.launch(Intent(this, LoginActivity::class.java)) bookViewerViewModel.setLoginCancelled(false) } else dataSource?.reload() @@ -129,8 +126,7 @@ class BookViewerActivity : AppCompatActivity(), BookViewerFragment.ReservationEv commitAllowingStateLoss() } if (bookViewerViewModel.loginCancelled.value!!){ - startActivityForResult(Intent(this, LoginActivity::class.java), - Constants.ACTIVITY_LOGIN_REQUEST_CODE) + openLoginActivity.launch(Intent(this, LoginActivity::class.java)) bookViewerViewModel.setLoginCancelled(false) } else dataSource?.reload() diff --git a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/MainActivity.kt b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/MainActivity.kt index ae0da95..bcbb185 100644 --- a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/MainActivity.kt +++ b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/MainActivity.kt @@ -11,6 +11,7 @@ import android.os.Bundle import android.provider.Settings import android.webkit.CookieManager import android.webkit.WebView +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AlertDialog import com.google.android.material.bottomnavigation.BottomNavigationView import androidx.appcompat.app.AppCompatActivity @@ -61,6 +62,32 @@ class MainActivity : AppCompatActivity(), ReservationsRecyclerFragment.Reservati if(key == getString(R.string.key_general_share_app_enabled)) invalidateOptionsMenu() } + val openLoginActivity = registerForActivityResult(ActivityResultContracts + .StartActivityForResult()){ result -> + if (result.resultCode == Activity.RESULT_OK){ + val user = result.data?.getStringExtra(Constants.CONNECTED_STATUS_USER_NAME) + if (!user.isNullOrEmpty()){ + homeViewModel.defineLoginStatus(true) + homeViewModel.defineConnectedUserName(user) + } + } + } + private val openSyncPermissionRequest = registerForActivityResult(ActivityResultContracts + .StartActivityForResult()){ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ + if (!Settings.canDrawOverlays(this)) + AlertDialog.Builder(this).apply { + setTitle(R.string.notification_sync_denied_title) + setMessage(R.string.notification_sync_denied_message) + setPositiveButton(R.string.dialog_button_ok, null) + }.create().show() + else { + startPowerSavingSettings() + setSyncSchedule() + } + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) @@ -112,35 +139,6 @@ class MainActivity : AppCompatActivity(), ReservationsRecyclerFragment.Reservati super.onDestroy() } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - when (requestCode){ - Constants.ACTIVITY_LOGIN_REQUEST_CODE -> { - if (resultCode == Activity.RESULT_OK){ - val user = data?.getStringExtra(Constants.CONNECTED_STATUS_USER_NAME) - if (!user.isNullOrEmpty()){ - homeViewModel.defineLoginStatus(true) - homeViewModel.defineConnectedUserName(user) - } - } - } - Constants.SYNC_PERMISSION_REQUEST_ID -> { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ - if (!Settings.canDrawOverlays(this)) - AlertDialog.Builder(this).apply { - setTitle(R.string.notification_sync_denied_title) - setMessage(R.string.notification_sync_denied_message) - setPositiveButton(R.string.dialog_button_ok, null) - }.create().show() - else { - startPowerSavingSettings() - setSyncSchedule() - } - } - } - } - } - override fun onRequestRefresh() { dataSource?.loadUrl(Constants.URL_LIBRARY_NEWEST) MessageSnackbar.make(container, R.string.snack_message_refreshing_newest, @@ -197,10 +195,7 @@ class MainActivity : AppCompatActivity(), ReservationsRecyclerFragment.Reservati if (loadingAlert.isShowing) loadingAlert.dismiss() if (prefs.getBoolean(getString(R.string.key_privacy_auto_login), true) && !homeViewModel.hasRequestedLogin.value!!) { - startActivityForResult( - Intent(this, LoginActivity::class.java), - Constants.ACTIVITY_LOGIN_REQUEST_CODE - ) + openLoginActivity.launch(Intent(this, LoginActivity::class.java)) homeViewModel.hasRequestedLogin.value = true } } @@ -256,7 +251,7 @@ class MainActivity : AppCompatActivity(), ReservationsRecyclerFragment.Reservati Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName")).also { if (packageManager.resolveActivity(it, PackageManager.MATCH_DEFAULT_ONLY) != null) - startActivityForResult(it, Constants.SYNC_PERMISSION_REQUEST_ID) + openSyncPermissionRequest.launch(it) } })) }.create().show() diff --git a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/SearchActivity.kt b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/SearchActivity.kt index 4f0857f..4db5fb2 100644 --- a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/SearchActivity.kt +++ b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/SearchActivity.kt @@ -1,6 +1,5 @@ package com.nintersoft.bibliotecaufabc.activities -import android.app.Activity import android.content.DialogInterface import android.content.Intent import android.os.Bundle @@ -13,6 +12,7 @@ import android.view.inputmethod.EditorInfo import android.webkit.WebView import android.widget.EditText import android.widget.LinearLayout +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.Observer @@ -39,6 +39,30 @@ class SearchActivity : AppCompatActivity() { private lateinit var searchViewModel : SearchViewModel private lateinit var messageViewModel : MessageViewModel + @Suppress("UNCHECKED_CAST") + private val openSearchFilterActivity = registerForActivityResult(ActivityResultContracts + .StartActivityForResult()){ result -> + if (result.resultCode == RESULT_OK && result.data != null){ + with(result.data!!){ + searchViewModel.setSearchField(getIntExtra(Constants.SEARCH_FILTER_FIELD, 0)) + searchViewModel.setSearchFilter(getSerializableExtra(Constants.SEARCH_FILTER_TYPE) + as ArrayList) + searchViewModel.setLibraryFilters(getSerializableExtra(Constants.SEARCH_FILTER_LIBRARY) + as ArrayList) + } + + AlertDialog.Builder(this).apply { + setTitle(R.string.dialog_filter_changed_title) + setMessage(R.string.dialog_filter_changed_message) + setNegativeButton(R.string.dialog_button_no, null) + setPositiveButton(R.string.dialog_button_yes, ({ _, _ -> + performNewSearch(searchViewModel.query.value!!) + })) + }.create().show() + } + } + + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_search) @@ -65,31 +89,6 @@ class SearchActivity : AppCompatActivity() { return super.onOptionsItemSelected(item) } - @Suppress("UNCHECKED_CAST") - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - - if (requestCode == Constants.ACTIVITY_SEARCH_FILTER_REQUEST_CODE - && resultCode == Activity.RESULT_OK && data != null){ - with(data){ - searchViewModel.setSearchField(getIntExtra(Constants.SEARCH_FILTER_FIELD, 0)) - searchViewModel.setSearchFilter(getSerializableExtra(Constants.SEARCH_FILTER_TYPE) - as ArrayList) - searchViewModel.setLibraryFilters(getSerializableExtra(Constants.SEARCH_FILTER_LIBRARY) - as ArrayList) - } - - AlertDialog.Builder(this).apply { - setTitle(R.string.dialog_filter_changed_title) - setMessage(R.string.dialog_filter_changed_message) - setNegativeButton(R.string.dialog_button_no, null) - setPositiveButton(R.string.dialog_button_yes, ({ _, _ -> - performNewSearch(searchViewModel.query.value!!) - })) - }.create().show() - } - } - private fun configureWebView(){ dataSource = WebView(this) Functions.configureWebView(dataSource!!, SearchWebClient(searchViewModel)) @@ -111,7 +110,7 @@ class SearchActivity : AppCompatActivity() { filters.putExtra(Constants.SEARCH_FILTER_TYPE, searchViewModel.searchFilter.value) filters.putExtra(Constants.SEARCH_FILTER_FIELD, searchViewModel.searchField.value!!) filters.putExtra(Constants.SEARCH_FILTER_LIBRARY, searchViewModel.searchLibrary.value) - startActivityForResult(filters, Constants.ACTIVITY_SEARCH_FILTER_REQUEST_CODE) + openSearchFilterActivity.launch(filters) } btn_more.setOnClickListener{ diff --git a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/SettingsActivity.kt b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/SettingsActivity.kt index 11639eb..b2cd18b 100644 --- a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/SettingsActivity.kt +++ b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/activities/SettingsActivity.kt @@ -100,7 +100,6 @@ class SettingsActivity : AppCompatActivity(), pref.fragment ).apply { arguments = args - setTargetFragment(caller, 0) } // Replace the existing Fragment with the new Fragment supportFragmentManager.beginTransaction() diff --git a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/global/Constants.kt b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/global/Constants.kt index 4cd89b8..d24e43b 100644 --- a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/global/Constants.kt +++ b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/global/Constants.kt @@ -59,17 +59,13 @@ object Constants { const val SYNC_EXECUTIONER_FIRST_DELAY_MIN : Long = 15 const val SYNC_REMINDER_NOTIFICATION_INTERVAL: Long = 5 - const val ACTIVITY_LOGIN_REQUEST_CODE = 11 const val ACTIVITY_RENEWAL_REQUEST_CODE = 13 - const val ACTIVITY_SEARCH_FILTER_REQUEST_CODE = 15 const val SYNC_NOTIFICATION_ID = 9000 const val SYNC_NOTIFICATION_UPDATE_ID = 9001 const val SYNC_NOTIFICATION_REVOKED_ID = 9002 const val SYNC_NOTIFICATION_REMINDER_ID = 9003 - const val SYNC_PERMISSION_REQUEST_ID = 10001 - val BOOK_COVER_PLACEHOLDERS = listOf(R.drawable.ic_book_cover_fill_01, R.drawable.ic_book_cover_fill_02, R.drawable.ic_book_cover_fill_03) diff --git a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/bookviewer/BookViewerFragment.kt b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/bookviewer/BookViewerFragment.kt index 2ba0625..7488b53 100644 --- a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/bookviewer/BookViewerFragment.kt +++ b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/bookviewer/BookViewerFragment.kt @@ -19,8 +19,8 @@ import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.request.RequestOptions import com.nintersoft.bibliotecaufabc.R +import com.nintersoft.bibliotecaufabc.activities.BookViewerActivity import com.nintersoft.bibliotecaufabc.activities.LoginActivity -import com.nintersoft.bibliotecaufabc.global.Constants import kotlinx.android.synthetic.main.fragment_book_viewer.* import org.json.JSONException import org.json.JSONObject @@ -67,8 +67,8 @@ class BookViewerFragment : Fragment() { listener = null } - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) buildLate() setListeners() } @@ -257,9 +257,8 @@ class BookViewerFragment : Fragment() { setMessage(R.string.dialog_warning_message_user_disconnected) setPositiveButton(R.string.dialog_button_yes, ({_ ,_ -> showLoadingAlert() - activity?.startActivityForResult(Intent(activity, - LoginActivity::class.java), - Constants.ACTIVITY_LOGIN_REQUEST_CODE) + (activity as BookViewerActivity?)?.openLoginActivity + ?.launch(Intent(activity, LoginActivity::class.java)) })) setNegativeButton(R.string.dialog_button_cancel, null) }.create().show() diff --git a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/home/HomeFragment.kt b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/home/HomeFragment.kt index e5451bf..2508fcc 100644 --- a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/home/HomeFragment.kt +++ b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/home/HomeFragment.kt @@ -124,8 +124,8 @@ class HomeFragment : Fragment() { @SuppressLint("QueryPermissionsNeeded") override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId){ - R.id.login -> activity?.startActivityForResult(Intent(context, - LoginActivity::class.java), Constants.ACTIVITY_LOGIN_REQUEST_CODE) + R.id.login -> (activity as MainActivity?)?.openLoginActivity + ?.launch(Intent(context, LoginActivity::class.java)) R.id.refresh -> listener?.onRequestRefresh() R.id.sign_out -> { item.isVisible = false diff --git a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/home/HomeViewAdapter.kt b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/home/HomeViewAdapter.kt index 4d4efaa..4d9cc42 100644 --- a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/home/HomeViewAdapter.kt +++ b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/home/HomeViewAdapter.kt @@ -59,9 +59,9 @@ class HomeViewAdapter : RecyclerView.Adapter BOOK_COVER_PLACEHOLDERS[position % Constants.BOOK_COVER_PLACEHOLDERS.size])). into(holder.bookCover!!) - holder.card?.setOnClickListener { _clickedBook.value = book } + holder.card?.setOnClickListener { _clickedBook.value = book!! } holder.card?.setOnLongClickListener { - _selectedBook.value = book + _selectedBook.value = book!! true } } diff --git a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/renewals/RenewalsFragment.kt b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/renewals/RenewalsFragment.kt index 12878c7..3444566 100644 --- a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/renewals/RenewalsFragment.kt +++ b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/renewals/RenewalsFragment.kt @@ -18,6 +18,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.snackbar.Snackbar import com.nintersoft.bibliotecaufabc.R import com.nintersoft.bibliotecaufabc.activities.LoginActivity +import com.nintersoft.bibliotecaufabc.activities.MainActivity import com.nintersoft.bibliotecaufabc.global.Constants import com.nintersoft.bibliotecaufabc.global.Functions import com.nintersoft.bibliotecaufabc.model.AppContext @@ -128,9 +129,8 @@ class RenewalsFragment : Fragment() { setTitle(R.string.dialog_warning_title) setMessage(R.string.dialog_warning_message_must_be_connected) setPositiveButton(R.string.dialog_button_yes, ({ _, _ -> - activity?.startActivityForResult( - Intent(requireActivity(), LoginActivity::class.java), - Constants.ACTIVITY_LOGIN_REQUEST_CODE) + (activity as MainActivity?)?.openLoginActivity + ?.launch(Intent(requireActivity(), LoginActivity::class.java)) })) setNegativeButton(R.string.dialog_button_no, null) }.create().show() diff --git a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/search/SearchViewAdapter.kt b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/search/SearchViewAdapter.kt index 9360680..9c34b66 100644 --- a/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/search/SearchViewAdapter.kt +++ b/BibliotecaUFABC/app/src/main/java/com/nintersoft/bibliotecaufabc/ui/search/SearchViewAdapter.kt @@ -61,10 +61,10 @@ class SearchViewAdapter (viewModel : SearchViewModel): BOOK_COVER_PLACEHOLDERS[position % Constants.BOOK_COVER_PLACEHOLDERS.size])). into(holder.bookCover!!) - holder.card?.setOnClickListener { _clickedBook.value = book } + holder.card?.setOnClickListener { _clickedBook.value = book!! } holder.card?.setOnLongClickListener { - _selectedBook.value = book + _selectedBook.value = book!! true }