Skip to content

Commit

Permalink
Merge pull request #14 from arindamxd/development
Browse files Browse the repository at this point in the history
Minimum SDK Version Rolled Back
  • Loading branch information
arindamxd authored Sep 11, 2023
2 parents 09d6ac6 + 8eb2df8 commit db4c884
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 123 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ dependencies {
implementation "androidx.exifinterface:exifinterface:1.3.6"

// Coil
implementation "io.coil-kt:coil:0.10.0"
implementation "io.coil-kt:coil:2.4.0"

// Material Design
implementation "com.google.android.material:material:1.9.0"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<!-- Declare permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
<!--<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />-->

<application
android:name=".CameraX"
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/java/com/arindam/camerax/ui/base/BaseActivity.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
package com.arindam.camerax.ui.base

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.viewbinding.ViewBinding
import com.arindam.camerax.ui.home.HomeActivity

/**
* Created by Arindam Karmakar on 17/04/20.
*/

abstract class BaseActivity : AppCompatActivity() {
abstract class BaseActivity<T : ViewBinding> : AppCompatActivity() {

protected lateinit var binding: T

override fun onCreate(savedInstanceState: Bundle?) {
if (this is HomeActivity) installSplashScreen()
super.onCreate(savedInstanceState)
provideLayout()?.let { setContentView(it) }
provideBinding().let {
if (it == null) setContentView(0)
else {
binding = it
setContentView(binding.root)
}
}
setupView(savedInstanceState)
}

open fun provideLayout(): View? = null
open fun provideBinding(): T? = null
abstract fun setupView(savedInstanceState: Bundle?)
}
32 changes: 16 additions & 16 deletions app/src/main/java/com/arindam/camerax/ui/base/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.IdRes
import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.navigation.NavDirections
import androidx.navigation.Navigation
import androidx.navigation.fragment.findNavController
import androidx.viewbinding.ViewBinding
import com.arindam.camerax.R
import com.arindam.camerax.util.commons.Constants.PERMISSIONS.REQUIRED_PERMISSIONS
import com.arindam.camerax.util.display.Toaster
Expand All @@ -24,32 +22,34 @@ import java.util.*
* Created by Arindam Karmakar on 17/04/20.
*/

abstract class BaseFragment : Fragment() {
abstract class BaseFragment<T : ViewBinding> : Fragment() {

protected lateinit var binding: T

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = provideView() ?: inflater.inflate(provideLayout(), container, false)
): View? = provideBinding().let {
return if (it == null) provideView()
else {
binding = it
binding.root
}
}

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

@LayoutRes
abstract fun provideLayout(): Int
abstract fun setupView(view: View, savedInstanceState: Bundle?)

open fun provideView(): View? = null
open fun provideBinding(): T? = null
open fun provideView(): View? = View(context)

protected fun navigateBack(@IdRes viewId: Int) {
Navigation.findNavController(requireActivity(), viewId).navigateUp()
}
abstract fun setupView(view: View, savedInstanceState: Bundle?)

protected fun navigate(navDirections: NavDirections) {
findNavController().navigate(navDirections)
}
protected fun navigate(directions: NavDirections) = findNavController().navigate(directions)
protected fun navigateBack() = findNavController().navigateUp()

/** Convenience method used to check if all permissions required by this app are granted */
protected fun hasPermissions() = REQUIRED_PERMISSIONS.all {
Expand Down
7 changes: 2 additions & 5 deletions app/src/main/java/com/arindam/camerax/ui/home/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.arindam.camerax.ui.home
import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.arindam.camerax.databinding.ActivityHomeBinding
import com.arindam.camerax.ui.base.BaseActivity
Expand All @@ -15,11 +14,9 @@ import com.arindam.camerax.util.commons.Constants
* Created by Arindam Karmakar on 17/04/20.
*/

class HomeActivity : BaseActivity() {
class HomeActivity : BaseActivity<ActivityHomeBinding>() {

val binding by lazy { ActivityHomeBinding.inflate(layoutInflater) }

override fun provideLayout(): View = binding.root
override fun provideBinding(): ActivityHomeBinding = ActivityHomeBinding.inflate(layoutInflater)

override fun setupView(savedInstanceState: Bundle?) {
// Empty
Expand Down
Loading

0 comments on commit db4c884

Please sign in to comment.