From c15c0b3d1b2143c5f7b0f91db0aebe67923b03d8 Mon Sep 17 00:00:00 2001 From: MahmoudMabrok Date: Sat, 18 May 2024 12:35:43 +0300 Subject: [PATCH 1/4] chore: remove old dependency and make app runnable --- app/build.gradle | 74 +-- app/src/main/AndroidManifest.xml | 7 +- .../quranyapp/datalayer/local/AyahItem.java | 85 ---- .../quranyapp/datalayer/local/AyahItem.kt | 47 ++ .../quranyapp/datalayer/local/SuraItem.java | 76 ---- .../quranyapp/datalayer/local/SuraItem.kt | 32 ++ .../datalayer/local/room/SurahDAO.kt | 4 +- .../feature/ayahs_search/ShowSearchResults.kt | 311 +++++++------ .../bookmark_fragment/BookmarkFragment.kt | 59 +-- .../feedback_activity/FeedbackActivity.java | 22 + .../quranyapp/feature/gotoscreen/GoToSurah.kt | 107 +++-- .../feature/home_Activity/HomeActivity.kt | 430 +++++++++--------- .../listening_activity/ListenFragment.kt | 400 +++++++++------- .../feature/{Login => login}/Login.java | 10 +- .../feature/read_log/ReadLogFragment.kt | 9 +- .../feature/setting/SettingActivity.kt | 92 ++-- .../feature/showSuraAyas/ShowAyahsActivity.kt | 121 ++--- .../show_sura_list/SuraListFragment.kt | 13 +- .../feature/show_tafseer/TafseerDetails.kt | 109 +++-- .../quranyapp/feature/splash/Splash.kt | 7 +- .../feature/test_quran/TestFragment.kt | 283 +++++++----- .../mahmoud/quranyapp/utils/Extensions.kt | 10 + app/src/main/res/layout/layout_login.xml | 8 +- build.gradle | 21 +- gradle.properties | 4 + gradle/wrapper/gradle-wrapper.jar | Bin 54329 -> 59536 bytes gradle/wrapper/gradle-wrapper.properties | 3 +- gradlew | 282 +++++++----- gradlew.bat | 43 +- 29 files changed, 1464 insertions(+), 1205 deletions(-) delete mode 100644 app/src/main/java/education/mahmoud/quranyapp/datalayer/local/AyahItem.java create mode 100644 app/src/main/java/education/mahmoud/quranyapp/datalayer/local/AyahItem.kt delete mode 100644 app/src/main/java/education/mahmoud/quranyapp/datalayer/local/SuraItem.java create mode 100644 app/src/main/java/education/mahmoud/quranyapp/datalayer/local/SuraItem.kt rename app/src/main/java/education/mahmoud/quranyapp/feature/{Login => login}/Login.java (89%) mode change 100644 => 100755 gradlew diff --git a/app/build.gradle b/app/build.gradle index 5cd7942..cab949b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,23 +1,24 @@ +import io.gitlab.arturbosch.detekt.Detekt + apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' apply plugin: "io.gitlab.arturbosch.detekt" - +apply plugin: 'kotlin-parcelize' android { - compileSdkVersion 29 + compileSdk 34 + defaultConfig { applicationId "education.mahmoud.quranyapp" minSdkVersion 21 - targetSdkVersion 29 - versionCode 30 - versionName "3.0.0" + targetSdkVersion 34 + versionCode 31 + versionName "3.0.1" multiDexEnabled true -// testInstrumentationRumannner "android.support.test.runner.AndroidJUnitRunner" - vectorDrawables.useSupportLibrary = true } + buildTypes { release { minifyEnabled true @@ -27,45 +28,46 @@ android { } sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } } compileOptions { - sourceCompatibility = '1.8' - targetCompatibility = '1.8' + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + kotlinOptions { + jvmTarget = JavaVersion.VERSION_17 } testOptions { unitTests.returnDefaultValues = true } - dataBinding { - enabled = true + + buildFeatures{ + viewBinding = true + dataBinding = true } + namespace 'education.mahmoud.quranyapp' } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.4.0-beta02' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0-beta02' - - - // kotlin - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test:runner:1.5.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' - - def support_version = '1.3.0' + def support_version = '1.6.1' implementation "androidx.appcompat:appcompat:$support_version" - implementation "com.google.android.material:material:$support_version" + def material_version = '1.12.0' + implementation "com.google.android.material:material:$material_version" - implementation 'androidx.core:core-ktx:1.5.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.core:core-ktx:1.13.1' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.android.support:multidex:1.0.3' implementation 'com.jakewharton:butterknife:10.1.0' annotationProcessor "com.jakewharton:butterknife-compiler:10.1.0" - // implementation "com.balsikandar.android:crashreporter:1.0.9" - implementation 'com.google.code.gson:gson:2.8.5' + implementation 'com.google.code.gson:gson:2.10.1' implementation 'com.intuit.sdp:sdp-android:1.0.6' implementation 'com.intuit.ssp:ssp-android:1.0.6' @@ -73,9 +75,9 @@ dependencies { implementation files('libs/AppRate_1.1.jar') // Room - implementation 'androidx.room:room-runtime:2.3.0' - kapt 'androidx.room:room-compiler:2.3.0' - implementation 'androidx.room:room-rxjava2:2.3.0' + implementation 'androidx.room:room-runtime:2.6.1' + kapt 'androidx.room:room-compiler:2.6.1' + implementation 'androidx.room:room-rxjava2:2.6.1' implementation 'pub.devrel:easypermissions:1.1.1' @@ -85,17 +87,17 @@ dependencies { implementation "com.github.ybq:Android-SpinKit:1.2.0" - implementation 'com.squareup.retrofit2:retrofit:2.7.2' - implementation 'com.squareup.retrofit2:converter-gson:2.3.0' + implementation 'com.squareup.retrofit2:retrofit:2.9.0' + implementation 'com.squareup.retrofit2:converter-gson:2.9.0' - implementation 'androidx.annotation:annotation:1.0.2' + implementation 'androidx.annotation:annotation:1.7.1' implementation 'com.jpardogo.materialtabstrip:library:1.0.6' implementation 'com.flipboard:bottomsheet-core:1.5.3' implementation 'com.flipboard:bottomsheet-commons:1.5.3' - implementation 'org.greenrobot:eventbus:3.1.1' + implementation 'org.greenrobot:eventbus:3.3.1' //rx @@ -122,18 +124,18 @@ dependencies { detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:1.18.1" - + implementation 'com.github.Zhuinden:fragmentviewbindingdelegate-kt:1.0.0' } apply plugin: "org.jlleitschuh.gradle.ktlint" -task detektFormat(type: io.gitlab.arturbosch.detekt.Detekt) { +tasks.register('detektFormat', Detekt) { description = "Runs autocorrect enabled detekt build." source = files("src/main/java") config.from(files("$rootDir/Scripts/detekt-config.yml")) autoCorrect = true reports { - html{ + html { enabled = true destination = file("build/reports/detekt-formatted.html") } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ebfea7b..255b6dd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools"> @@ -21,6 +20,7 @@ tools:ignore="UnusedAttribute" tools:replace="allowBackup"> @@ -52,6 +52,7 @@ @@ -82,7 +83,7 @@ android:exported="true" android:theme="@style/AppTheme.NoActionBar" android:windowSoftInputMode="adjustPan" /> - + diff --git a/app/src/main/java/education/mahmoud/quranyapp/feature/ayahs_search/ShowSearchResults.kt b/app/src/main/java/education/mahmoud/quranyapp/feature/ayahs_search/ShowSearchResults.kt index 834442c..8970e2f 100644 --- a/app/src/main/java/education/mahmoud/quranyapp/feature/ayahs_search/ShowSearchResults.kt +++ b/app/src/main/java/education/mahmoud/quranyapp/feature/ayahs_search/ShowSearchResults.kt @@ -10,8 +10,11 @@ import android.view.View import android.view.ViewGroup import android.widget.Toast import com.flipboard.bottomsheet.commons.MenuSheetView +import com.zhuinden.fragmentviewbindingdelegatekt.viewBinding import education.mahmoud.quranyapp.R import education.mahmoud.quranyapp.base.BaseFragment +import education.mahmoud.quranyapp.databinding.ActivityShowSearchResultsBinding +import education.mahmoud.quranyapp.databinding.HeaderSearchBinding import education.mahmoud.quranyapp.datalayer.QuranRepository import education.mahmoud.quranyapp.datalayer.local.room.AyahItem import education.mahmoud.quranyapp.feature.listening_activity.AyahsListen @@ -19,159 +22,169 @@ import education.mahmoud.quranyapp.feature.listening_activity.ListenServie import education.mahmoud.quranyapp.feature.showSuraAyas.ShowAyahsActivity import education.mahmoud.quranyapp.utils.Constants import education.mahmoud.quranyapp.utils.Util -import kotlinx.android.synthetic.main.activity_show_search_results.* -import kotlinx.android.synthetic.main.header_search.* import org.koin.java.KoinJavaComponent import java.util.* // ktlint-disable no-wildcard-imports class ShowSearchResults : BaseFragment() { - private var adapter = SearchResultsAdapter() - - private val repository = KoinJavaComponent.get(QuranRepository::class.java) - private var ayahItems: List = listOf() - private var ayah: String = "" - var isRunning = false - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.activity_show_search_results, container, false) - } - - override fun initViews(view: View) { - super.initViews(view) - initRv() - adapterListeners() - editWatcher() - setClickListeners() - } - - override fun setClickListeners() { - super.setClickListeners() - - imSearch.setOnClickListener { - doSearch("${edSearch.text}") - } - } - - private fun editWatcher() { - edSearch?.addTextChangedListener(object : TextWatcher { - override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {} - override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {} - override fun afterTextChanged(editable: Editable) { - doSearch(editable.toString()) - } - }) - } - - private fun doSearch(text: String?) { - ayah = text ?: "" - ayah = ayah.replace(" +".toRegex(), " ") - if (ayah.isNotEmpty()) { - ayahItems = repository.getAyahByAyahText(ayah) - Log.d(TAG, "afterTextChanged: " + ayahItems.size) - val count = ayahItems.size // n of results - tvSearchCount?.text = getString(R.string.times, count) - if (count > 0) { - adapter.setAyahItemList(ayahItems, ayah) - foundState() - } else { - notFoundState() - } - } else { - defaultState() - } - } - - private fun setUpBottomSheet(ayahItem: AyahItem) { // bottom sheet - val menuSheetView = MenuSheetView( - requireContext(), MenuSheetView.MenuType.LIST, "Options", - MenuSheetView.OnMenuItemClickListener { item -> - if (bottomSearch.isSheetShowing) { - bottomSearch?.dismissSheet() - } - when (item.itemId) { - R.id.menuOpen -> openPage(ayahItem.pageNum) - R.id.menuPlaySound -> playAudio(ayahItem) - R.id.menuTafser -> showTafseer(ayahItem) - } - true + private var adapter = SearchResultsAdapter() + + private val repository = KoinJavaComponent.get(QuranRepository::class.java) + private var ayahItems: List = listOf() + private var ayah: String = "" + var isRunning = false + + private val binding by viewBinding(ActivityShowSearchResultsBinding::bind) + private val searchBinding by viewBinding(HeaderSearchBinding::bind) + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle?, + ): View? { + return inflater.inflate(R.layout.activity_show_search_results, container, false) + } + + override fun initViews(view: View) { + super.initViews(view) + initRv() + adapterListeners() + editWatcher() + setClickListeners() + } + + override fun setClickListeners() { + super.setClickListeners() + + searchBinding.imSearch.setOnClickListener { + doSearch("${searchBinding.edSearch.text}") + } + } + + private fun editWatcher() { + searchBinding.edSearch.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {} + override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {} + override fun afterTextChanged(editable: Editable) { + doSearch(editable.toString()) + } + }) + } + + private fun doSearch(text: String?) { + ayah = text ?: "" + ayah = ayah.replace(" +".toRegex(), " ") + if (ayah.isNotEmpty()) { + ayahItems = repository.getAyahByAyahText(ayah) + Log.d(TAG, "afterTextChanged: " + ayahItems.size) + val count = ayahItems.size // n of results + binding.tvSearchCount.text = getString(R.string.times, count) + if (count > 0) { + adapter.setAyahItemList(ayahItems, ayah) + foundState() + } else { + notFoundState() + } + } else { + defaultState() + } + } + + private fun setUpBottomSheet(ayahItem: AyahItem) { // bottom sheet + val menuSheetView = MenuSheetView( + requireContext(), MenuSheetView.MenuType.LIST, "Options", + MenuSheetView.OnMenuItemClickListener { item -> + if (binding.bottomSearch.isSheetShowing) { + binding.bottomSearch.dismissSheet() + } + when (item.itemId) { + R.id.menuOpen -> openPage(ayahItem.pageNum) + R.id.menuPlaySound -> playAudio(ayahItem) + R.id.menuTafser -> showTafseer(ayahItem) + } + true + } + ) + menuSheetView.inflateMenu(R.menu.menu_sheet_search) + binding.bottomSearch.showWithSheetView(menuSheetView) + } + + private fun showTafseer(ayahItem: AyahItem) { + val title = this.getString( + R.string.tafserr_info, + ayahItem.ayahInSurahIndex, + ayahItem.pageNum, + ayahItem.juz + ) + Util.getDialog(requireContext(), ayahItem.tafseer, title).show() + } + + private fun adapterListeners() { + adapter.setiSearchItemClick(object : SearchResultsAdapter.ISearchItemClick { + override fun onSearchItemClick(item: AyahItem?) { + item?.let { setUpBottomSheet(item) } + Log.d(TAG, "onSearchItemClick: ") + } + }) + } + + private fun openPage(pageNum: Int) { + activity?.let { + val openAcivity = Intent(requireContext(), ShowAyahsActivity::class.java) + openAcivity.putExtra(Constants.PAGE_INDEX, pageNum) + startActivity(openAcivity) } - ) - menuSheetView.inflateMenu(R.menu.menu_sheet_search) - bottomSearch?.showWithSheetView(menuSheetView) - } - - private fun showTafseer(ayahItem: AyahItem) { - val title = this.getString(R.string.tafserr_info, ayahItem.ayahInSurahIndex, ayahItem.pageNum, ayahItem.juz) - Util.getDialog(requireContext(), ayahItem.tafseer, title).show() - } - - private fun adapterListeners() { - adapter.setiSearchItemClick(object : SearchResultsAdapter.ISearchItemClick { - override fun onSearchItemClick(item: AyahItem?) { - item?.let { setUpBottomSheet(item) } - Log.d(TAG, "onSearchItemClick: ") - } - }) - } - - private fun openPage(pageNum: Int) { - activity?.let { - val openAcivity = Intent(requireContext(), ShowAyahsActivity::class.java) - openAcivity.putExtra(Constants.PAGE_INDEX, pageNum) - startActivity(openAcivity) - } - } - - /** - * state with no search performed - */ - private fun defaultState() { - tvNotFound?.visibility = View.GONE - } - - private fun initRv() { - rvSearch?.adapter = adapter - rvSearch?.setHasFixedSize(true) - } - - private fun foundState() { - rvSearch?.visibility = View.VISIBLE - tvNotFound?.visibility = View.GONE - } - - private fun notFoundState() { - rvSearch?.visibility = View.GONE - tvNotFound?.visibility = View.VISIBLE - } - - var serviceIntent: Intent? = null - - private fun playAudio(item: AyahItem) { - if (item.audioPath != null) { - Log.d(TAG, "playAudio: isRunning $isRunning") - val ayahItems: MutableList = ArrayList() - ayahItems.add(item) - val ayahsListen = AyahsListen() - ayahsListen.ayahItemList = ayahItems - if (serviceIntent != null) { - requireContext().stopService(serviceIntent) - } - serviceIntent = ListenServie.createService( - requireActivity().applicationContext, - ayahsListen - ) - } else { - showMessage(getString(R.string.not_downlod_audio)) - } - } - - private fun showMessage(message: String) { - Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show() - } - - companion object { - private const val TAG = "ShowSearchResults" - private const val RC_STORAGE = 10002 - } + } + + /** + * state with no search performed + */ + private fun defaultState() { + binding.tvNotFound.visibility = View.GONE + } + + private fun initRv() { + binding.rvSearch.adapter = adapter + binding.rvSearch.setHasFixedSize(true) + } + + private fun foundState() { + binding.rvSearch.visibility = View.VISIBLE + binding.tvNotFound.visibility = View.GONE + } + + private fun notFoundState() { + binding.rvSearch.visibility = View.GONE + binding.tvNotFound.visibility = View.VISIBLE + } + + var serviceIntent: Intent? = null + + private fun playAudio(item: AyahItem) { + if (item.audioPath != null) { + Log.d(TAG, "playAudio: isRunning $isRunning") + val ayahItems: MutableList = ArrayList() + ayahItems.add(item) + val ayahsListen = AyahsListen() + ayahsListen.ayahItemList = ayahItems + if (serviceIntent != null) { + requireContext().stopService(serviceIntent) + } + serviceIntent = ListenServie.createService( + requireActivity().applicationContext, + ayahsListen + ) + } else { + showMessage(getString(R.string.not_downlod_audio)) + } + } + + private fun showMessage(message: String) { + Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show() + } + + companion object { + private const val TAG = "ShowSearchResults" + private const val RC_STORAGE = 10002 + } } diff --git a/app/src/main/java/education/mahmoud/quranyapp/feature/bookmark_fragment/BookmarkFragment.kt b/app/src/main/java/education/mahmoud/quranyapp/feature/bookmark_fragment/BookmarkFragment.kt index 23d4cd3..36e142f 100644 --- a/app/src/main/java/education/mahmoud/quranyapp/feature/bookmark_fragment/BookmarkFragment.kt +++ b/app/src/main/java/education/mahmoud/quranyapp/feature/bookmark_fragment/BookmarkFragment.kt @@ -6,8 +6,10 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.ethanhua.skeleton.Skeleton +import com.zhuinden.fragmentviewbindingdelegatekt.viewBinding import education.mahmoud.quranyapp.R import education.mahmoud.quranyapp.base.DataLoadingBaseFragment +import education.mahmoud.quranyapp.databinding.FragmentBookmarkBinding import education.mahmoud.quranyapp.datalayer.QuranRepository import education.mahmoud.quranyapp.feature.showSuraAyas.ShowAyahsActivity import education.mahmoud.quranyapp.utils.Constants @@ -15,14 +17,17 @@ import education.mahmoud.quranyapp.utils.bind import education.mahmoud.quranyapp.utils.log import education.mahmoud.quranyapp.utils.show import io.reactivex.rxkotlin.addTo -import kotlinx.android.synthetic.main.fragment_bookmark.* import org.koin.android.ext.android.inject class BookmarkFragment : DataLoadingBaseFragment() { private val quranRepository: QuranRepository by inject() private val bookmarkAdapter by lazy { BookmarkAdapter() } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle?, + ): View? { return inflater.inflate(R.layout.fragment_bookmark, container, false) } @@ -31,8 +36,10 @@ class BookmarkFragment : DataLoadingBaseFragment() { initRv() } + private val binding by viewBinding(FragmentBookmarkBinding::bind) + private fun initRv() { - rvBookmark.adapter = bookmarkAdapter + binding.rvBookmark.adapter = bookmarkAdapter bookmarkAdapter.setIoBookmark { item -> val openAcivity = Intent(context, ShowAyahsActivity::class.java) openAcivity.putExtra(Constants.PAGE_INDEX, item.pageNum) @@ -44,39 +51,39 @@ class BookmarkFragment : DataLoadingBaseFragment() { context?.show(getString(R.string.deleted)) } - Skeleton.bind(rvBookmark) - .adapter(bookmarkAdapter) - .load(R.layout.bookmark_skelton) - .show() - .apply { - hide() - addSketlon(this) - } + Skeleton.bind(binding.rvBookmark) + .adapter(bookmarkAdapter) + .load(R.layout.bookmark_skelton) + .show() + .apply { + hide() + addSketlon(this) + } } override fun startLoadingData() { super.startLoadingData() quranRepository.bookmarks.bind() - .doAfterNext { - hideLoad() + .doAfterNext { + hideLoad() + } + .subscribe({ + "$it".log() + if (it.isEmpty()) { + noDataState() } - .subscribe({ - "$it".log() - if (it.isEmpty()) { - noDataState() - } - bookmarkAdapter.setBookmarkItemList(it) - }, { - val msg = it.message ?: "Error " - context?.show(msg) - }) - .addTo(bg) + bookmarkAdapter.setBookmarkItemList(it) + }, { + val msg = it.message ?: "Error " + context?.show(msg) + }) + .addTo(bg) } override fun noDataState() { super.noDataState() - rvBookmark.visibility = View.GONE - tvNoBookMark.visibility = View.VISIBLE + binding.rvBookmark.visibility = View.GONE + binding.tvNoBookMark.visibility = View.VISIBLE } companion object { diff --git a/app/src/main/java/education/mahmoud/quranyapp/feature/feedback_activity/FeedbackActivity.java b/app/src/main/java/education/mahmoud/quranyapp/feature/feedback_activity/FeedbackActivity.java index a4ca21c..b11c7ae 100644 --- a/app/src/main/java/education/mahmoud/quranyapp/feature/feedback_activity/FeedbackActivity.java +++ b/app/src/main/java/education/mahmoud/quranyapp/feature/feedback_activity/FeedbackActivity.java @@ -1,6 +1,7 @@ package education.mahmoud.quranyapp.feature.feedback_activity; import android.os.Bundle; +import android.view.WindowManager; import android.widget.Button; import android.widget.Toast; @@ -44,6 +45,27 @@ protected void onCreate(Bundle savedInstanceState) { } + @Override + protected void onPause() { + super.onPause(); + Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show(); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + + @Override + protected void onStop() { + super.onStop(); + Toast.makeText(this, "onStop", Toast.LENGTH_SHORT).show(); + // getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } + + @Override + protected void onResume() { + super.onResume(); + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); + Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show(); + } + @OnClick(R.id.btnSendFeedback) public void onViewClicked() { diff --git a/app/src/main/java/education/mahmoud/quranyapp/feature/gotoscreen/GoToSurah.kt b/app/src/main/java/education/mahmoud/quranyapp/feature/gotoscreen/GoToSurah.kt index 3e128a1..01b29d2 100644 --- a/app/src/main/java/education/mahmoud/quranyapp/feature/gotoscreen/GoToSurah.kt +++ b/app/src/main/java/education/mahmoud/quranyapp/feature/gotoscreen/GoToSurah.kt @@ -6,14 +6,21 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.DialogFragment +import com.zhuinden.fragmentviewbindingdelegatekt.viewBinding import education.mahmoud.quranyapp.R +import education.mahmoud.quranyapp.databinding.GoToSuraBinding import education.mahmoud.quranyapp.feature.showSuraAyas.ShowAyahsActivity import education.mahmoud.quranyapp.utils.Constants -import kotlinx.android.synthetic.main.go_to_sura.* class GoToSurah : DialogFragment() { - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + private val binding by viewBinding(GoToSuraBinding::bind) + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle?, + ): View? { return inflater.inflate(R.layout.go_to_sura, container) } @@ -24,37 +31,41 @@ class GoToSurah : DialogFragment() { } private fun setClickListners() { - btnGo.setOnClickListener { - onViewClicked() - } + with(binding) { + btnGo.setOnClickListener { + onViewClicked() + } - btnGoToJuz.setOnClickListener { - onJuz() - } + btnGoToJuz.setOnClickListener { + onJuz() + } - btnGoToPage.setOnClickListener { - onbtnGoToPage() + btnGoToPage.setOnClickListener { + onbtnGoToPage() + } } } fun onViewClicked() { val index: Int - index = try { - edSurahNum.text.toString().toInt() - } catch (e: NumberFormatException) { - 1 - } - val ayahIndex: Int - ayahIndex = try { - edSurahAyahNum.text.toString().toInt() - } catch (e: NumberFormatException) { - 1 - } - if (index < 1 || index > 114) { - edSurahNum.error = "Number must be 1-114" - return + with(binding) { + index = try { + edSurahNum.text.toString().toInt() + } catch (e: NumberFormatException) { + 1 + } + val ayahIndex: Int + ayahIndex = try { + edSurahAyahNum.text.toString().toInt() + } catch (e: NumberFormatException) { + 1 + } + if (index < 1 || index > 114) { + edSurahNum.error = "Number must be 1-114" + return + } + goToSura(index, ayahIndex) } - goToSura(index, ayahIndex) } /* public void goByName() { @@ -78,17 +89,19 @@ class GoToSurah : DialogFragment() { } fun onJuz() { - var index = 0 - index = try { - edJuz.text.toString().toInt() - } catch (e: NumberFormatException) { - 1 - } - if (index < 1 || index > 30) { - edJuz.error = "Number must be 1-30" - return + with(binding) { + var index = 0 + index = try { + edJuz.text.toString().toInt() + } catch (e: NumberFormatException) { + 1 + } + if (index < 1 || index > 30) { + edJuz.error = "Number must be 1-30" + return + } + goToJuz(index) } - goToJuz(index) } private fun goToJuz(index: Int) { @@ -99,18 +112,20 @@ class GoToSurah : DialogFragment() { } fun onbtnGoToPage() { - try { - val page: Int = edPage.text.toString().toInt() - if (page > 0 && page <= 604) { - val intent = Intent(activity, ShowAyahsActivity::class.java) - intent.putExtra(Constants.PAGE_INDEX, page) - startActivity(intent) - dismiss() - } else { - edPage.error = getString(R.string.page_limit) + with(binding) { + try { + val page: Int = edPage.text.toString().toInt() + if (page > 0 && page <= 604) { + val intent = Intent(activity, ShowAyahsActivity::class.java) + intent.putExtra(Constants.PAGE_INDEX, page) + startActivity(intent) + dismiss() + } else { + edPage.error = getString(R.string.page_limit) + } + } catch (e: NumberFormatException) { + e.printStackTrace() } - } catch (e: NumberFormatException) { - e.printStackTrace() } } } diff --git a/app/src/main/java/education/mahmoud/quranyapp/feature/home_Activity/HomeActivity.kt b/app/src/main/java/education/mahmoud/quranyapp/feature/home_Activity/HomeActivity.kt index be3be41..0ac634d 100644 --- a/app/src/main/java/education/mahmoud/quranyapp/feature/home_Activity/HomeActivity.kt +++ b/app/src/main/java/education/mahmoud/quranyapp/feature/home_Activity/HomeActivity.kt @@ -17,6 +17,7 @@ import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.google.android.material.tabs.TabLayoutMediator import education.mahmoud.quranyapp.R +import education.mahmoud.quranyapp.databinding.ActivityHomeBinding import education.mahmoud.quranyapp.datalayer.QuranRepository import education.mahmoud.quranyapp.feature.ayahs_search.ShowSearchResults import education.mahmoud.quranyapp.feature.download.DownloadActivity @@ -31,218 +32,231 @@ import education.mahmoud.quranyapp.feature.show_tafseer.TafseerDetails import education.mahmoud.quranyapp.feature.splash.Splash import education.mahmoud.quranyapp.feature.test_quran.TestFragment import education.mahmoud.quranyapp.utils.Constants -import kotlinx.android.synthetic.main.activity_home.* +import education.mahmoud.quranyapp.utils.viewBinding import org.koin.android.ext.android.inject import pub.devrel.easypermissions.EasyPermissions import pub.devrel.easypermissions.PermissionRequest class HomeActivity : AppCompatActivity() { - private var isPermissionAllowed: Boolean = false - private val quranRepository: QuranRepository by inject() - var ahays = 0 - - private var currentID = 0 - - private val tafseerFragment by lazy { TafseerDetails() } - private val listenFragment by lazy { ListenFragment() } - private val readLogFragment by lazy { ReadLogFragment() } - private val testFragment by lazy { TestFragment() } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_home) - - goToSplash() - ahays = quranRepository.totlaAyahs - - toolbar?.let { setSupportActionBar(it) } - - setupVP() - } - - private fun setupVP() { - val adapter = HomeVPAdapter(this) - vpHome.adapter = adapter - val titles = resources.getStringArray(R.array.home_tabs) - TabLayoutMediator(tabHome, vpHome) { tab, pos -> - tab.text = titles[pos] - Log.i("TestTest", "HomeActivity setupVP ${titles[pos]}") - }.attach() - } - - fun afterSplash() { - supportFragmentManager.popBackStackImmediate() - openRead() - // checkLastReadAndDisplayDialoge() - } - - private fun determineToOpenOrNotSplash() { - Log.d(TAG, "determineToOpenOrNotSplash: n $ahays") - if (ahays == 0) { - Log.d(TAG, "determineToOpenOrNotSplash: ok $ahays") - goToSplash() - } - } - - private fun checkLastReadAndDisplayDialoge() { - val last = quranRepository.latestRead - Log.d(TAG, "checkLastReadAndDisplayDialoge: $last") - if (last >= 0) { - displayDialoge(last) - Log.d(TAG, "checkLastReadAndDisplayDialoge: @@ ") - } - } - - private fun displayDialoge(last: Int) { - Log.d(TAG, "displayDialoge: ") - val dialog = Dialog(this) - val view = LayoutInflater.from(this).inflate(R.layout.last_read_dialoge, null) - val button = view.findViewById