Skip to content

rajputmukesh748/Android-MVVM-Latest-Template

Repository files navigation

Android-MVVM-Latest-Template

Hello Developers.......

This android template used only for help to setup android project with all latest features. You just need to change package name and enjoye this template. Hope it's very helpfull to all new users or developers.

Features

  1. Used Kotlin with latest MVVM architecture
  2. Use JAVA-11 for run this project
  3. Repository pattern for call REST Api's
  4. Easy Data Storefor save local data with coroutines
  5. Easy to use sockets
  6. Error Handling and Memory Management
  7. Dexter for handle runtime permissions
  8. Generic Adapters
  9. Common extention functions for convert date format, price format, first letter capital

Let's start to introduce all features one by one.

Whole project used Dependency Injection (Hilt) with View Binding

Controller Package

Controller class
1. AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)

This is used for app always show light mode. If your phone used dark mode then your app always used light mode. You can remove this line if you want to add NIGHT mode in your app.



2. FontsOverride.setDefaultFont(this, "SERIF", "app_fonts.ttf")

This call used for change whole app or all Third Party font. simply pass font name which present in "assets" folder in your app. Automatically change whole app font. If you want to add multiple fonts you can simply add more lines only chnage "SERIF" into different names and also declare in your theme file.



3. registerActivityLifecycleCallbacks(this)

This line only used for when your current activity change there lifecycle position then you can listen directly in your controller class.



4. CallDataStore.initializeDataStore(context = applicationContext,dataBaseName = applicationContext.packageName)

This is used for initialize data store. This app used my own dependency for use data store. It's already handles coroutines or singleton. It's easy to use.



5. FacebookSdk.fullyInitialize()
    AppEventsLogger.activateApp(this)

This is only for initialize full facebook SDK. If you want to do this then please uncomment it.



6. Thread.setDefaultUncaughtExceptionHandler(this)

This is used for handle any exception in your app. If your app crash or throw any exception you can direclty handle inside this block and generate a customer report same like Firebase Crashlytics.

Common Classes Package

1. Generic Adapter

Generic Adapter with DiffUtils or View Binding

DiffUtil is a utility class that calculates the difference between two lists and outputs a list of update operations that converts the first list into the second one.

How to use Generic Adapter

   val adapter = object : GenericAdapter<DemoBinding, String>() {
      override fun onCreateView(parent: ViewGroup, viewType: Int) =
          DemoBinding.inflate(LayoutInflater.from(parent.context), parent, false)

      override fun onBindHolder(holder: DemoBinding, dataClass: String) {
          //Hadnle your data or set UI with holder or Data Class
      }
  }

How pass list in Generic Adapter

    adapter.submitList(listOf("Mukesh", "Kotlin", "Code"))

2. GenericFragmentAdapter

If you want to show multple fragments in viewpager with sliding feature. Then no need to generate a new adapter every time. We provide one generic adapter for handle all this feature.

How to use Generic Fragment Adapter

viewPagerId.adapter = GenericFragmentAdapter(this).apply{
  //Pass Fragment Classes
  submitList(UpCommingBooking(), PastBooking(), Cancel Booking())
}

3. OtpTimer

Mostly in every app need to show timer. Basically for OTP 30 second. Everytime it takes time to hanle this. but now it's easy to use. you just set timer

How to implemet OTP Timer

First need to implement interface in your class and initialize it.

   class VerifyOtp: SendOtpTimerData{ 
      override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        .....
        OtpTimer.sendOtpTimerData = this
      }
    
      override fun otpData(time: String){
        //Here you get time every second
      }
    }

Change maximum time.

      OtpTimer.setMaxTime(30, OtpTimeType.SECOND)

Change Time interval.

//Every one second

     OtpTimer.setMaxTime(1, OtpTimeType.SECOND)

OTP Time Types.

      enum class OtpTimeType{
          // @MILLISECOND [setMaxTime] 30000 for 30 second timer
          MILLISECOND,
          // @SECOND [setMaxTime] 30 for 30 second timer
          SECOND,
          // @MINUTE [setMaxTime] 1 for 1 minute timer 
          MINUTE,
          // @HOURS [setMaxTime] 1 for 1 hour timer
          HOURS,
          // @DAYS [setMaxTime] 1 for 1 day timer
          DAYS
      }

How to start timer

      OtpTimer.startTimer()

How to stop timer

      OtpTimer.stopTimer()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages