Skip to content

Commit

Permalink
fix navigation bug 🔨🔨
Browse files Browse the repository at this point in the history
  • Loading branch information
hamza94max committed Jan 9, 2024
1 parent 077eac1 commit f57563c
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 74 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {

defaultConfig {
applicationId "com.islamey.wazkar"
minSdkVersion 26
minSdkVersion 25
targetSdkVersion 33
versionCode 1
versionName "1.0.0"
Expand Down
Binary file removed app/release/release/Wazaker.aab
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.islamey.hamza.wazaker.ui.HomeFragment

import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
Expand Down Expand Up @@ -41,7 +42,9 @@ class HomeFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

hijriViewModel.getHijriDate(getCurrentDate())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
hijriViewModel.getHijriDate(getCurrentDate())
}

initUI()

Expand Down
76 changes: 4 additions & 72 deletions app/src/main/java/com/islamey/hamza/wazaker/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.islamey.hamza.wazaker.ui

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import com.hassanjamil.hqibla.CompassActivity
import com.hassanjamil.hqibla.Constants
import androidx.navigation.ui.setupWithNavController
import com.islamey.hamza.wazaker.utils.Notifications.setupNotification
import com.islamey.hamza.wazaker.utils.Utils.getDarkModeState
import com.islamey.wazkar.R
Expand All @@ -20,13 +16,6 @@ import dagger.hilt.android.AndroidEntryPoint
class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding
private val navController: NavController by lazy {
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.hostFragment) as NavHostFragment
navHostFragment.navController
}

private var lastOpenedScreenId = R.id.home_action

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
Expand All @@ -48,66 +37,9 @@ class MainActivity : AppCompatActivity() {
}

private fun setUpBottomViewNavigation() {
binding.bottomNavigationView.setOnItemSelectedListener { menuItem ->
when (menuItem.itemId) {
R.id.home_action -> {
doIfNotCurrent(R.id.home_action){
navController.navigate(R.id.homeFragment)
}
true
}

R.id.qibla_action -> {
openQiblaActivity()
// as we open another activity we should not lose current selection
false
}

R.id.forty_action -> {
doIfNotCurrent(R.id.forty_action){
navController.navigate(R.id.fortyHadithListFragment)
}
true
}

R.id.settings_action -> {
doIfNotCurrent(R.id.settings_action){
navController.navigate(R.id.settingsFragment)
}
true
}

else -> false
}
}
}

private fun doIfNotCurrent(actionId: Int, action : ()-> Unit) {
if (actionId != lastOpenedScreenId){
action.invoke()
lastOpenedScreenId = actionId
}
}

private fun openQiblaActivity() {
val intent = Intent(this, CompassActivity::class.java)
intent.putExtra(Constants.TOOLBAR_BG_COLOR, "#FFFFFF") // Toolbar Background color
intent.putExtra(Constants.COMPASS_BG_COLOR, "#FFFFFF") // Compass background color
intent.putExtra(Constants.ANGLE_TEXT_COLOR, "#000000") // Angle Text color
intent.putExtra(Constants.DRAWABLE_DIAL, R.drawable.dial) // Your dial drawable resource
intent.putExtra(
Constants.DRAWABLE_QIBLA,
R.drawable.qibla
) // Your qibla indicator drawable resource
intent.putExtra(
Constants.FOOTER_IMAGE_VISIBLE,
View.VISIBLE or View.INVISIBLE or View.GONE
) // Footer World Image visibility
intent.putExtra(
Constants.LOCATION_TEXT_VISIBLE,
View.VISIBLE or View.INVISIBLE or View.GONE
) // Location Text visibility
startActivity(intent)
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.hostFragment) as NavHostFragment
binding.bottomNavigationView.setupWithNavController(navHostFragment.navController)
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.islamey.hamza.wazaker.ui.qibla

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.hassanjamil.hqibla.CompassActivity
import com.hassanjamil.hqibla.Constants
import com.islamey.wazkar.databinding.FragmentQiblaBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class QiblaFragment : Fragment() {

private var _binding: FragmentQiblaBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentQiblaBinding.inflate(layoutInflater)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

openQiblaActivity()
}

private fun openQiblaActivity() {
val intent = Intent(requireContext(), CompassActivity::class.java)
intent.putExtra(Constants.TOOLBAR_BG_COLOR, "#FFFFFF") // Toolbar Background color
intent.putExtra(Constants.COMPASS_BG_COLOR, "#FFFFFF") // Compass background color
intent.putExtra(Constants.ANGLE_TEXT_COLOR, "#000000") // Angle Text color
startActivity(intent)
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/com/islamey/hamza/wazaker/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package com.islamey.hamza.wazaker.utils

import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.annotation.RequiresApi
import com.islamey.hamza.wazaker.domain.Models.HijriDateResponse
import org.apache.commons.lang3.StringEscapeUtils
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.*

object Utils {

@RequiresApi(Build.VERSION_CODES.O)
fun getCurrentDate(): String {
val currentDate = LocalDate.now()
val formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy")
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/fragment_qibla.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.islamey.hamza.wazaker.ui.qibla.QiblaFragment">


</FrameLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,10 @@
android:name="com.islamey.hamza.wazaker.ui.settings.SettingsFragment"
android:label="fragment_settings"
tools:layout="@layout/fragment_settings" />
<fragment
android:id="@+id/qiblaFragment"
android:name="com.islamey.hamza.wazaker.ui.qibla.QiblaFragment"
android:label="fragment_qibla"
tools:layout="@layout/fragment_qibla" />

</navigation>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ buildscript {

plugins {
id 'com.google.dagger.hilt.android' version '2.44' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}

allprojects {
Expand Down

0 comments on commit f57563c

Please sign in to comment.