Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Demo/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
}

android {
Expand Down Expand Up @@ -40,6 +41,8 @@ android {

dependencies {
def lifecycle_version = "2.6.1"
def nav_version = "2.5.3"

implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
Expand All @@ -49,6 +52,12 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.core:core-splashscreen:1.0.1"
implementation "androidx.preference:preference-ktx:1.2.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1"
implementation 'androidx.fragment:fragment-ktx:1.5.7'

// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Expand Down
87 changes: 79 additions & 8 deletions Demo/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />

<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />

<application
android:name=".DemoApplication"
android:allowBackup="true"
Expand All @@ -10,36 +20,97 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.App.Starting"
android:theme="@style/Theme.Blue"
tools:targetApi="31">

<activity
android:name=".MainActivity"
android:exported="true" />

<activity
android:name=".stackexchange.StackExchangeActivity"
android:exported="true"
android:theme="@style/Theme.StackExchange">
android:theme="@style/Theme.StackExchange" />

<activity
android:name="com.krunal.demo.searchwebview.ui.activities.SearchWebActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".UIComponentsActivity"
android:exported="true">
android:name=".appcomponents.ui.activities.ImagePickerActivity"
android:exported="true"
android:label="DemoImagePicker"
android:taskAffinity="com.krunal.demo.imagePicker">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
</intent-filter>
</activity>

<category android:name="android.intent.category.LAUNCHER" />
<activity
android:name=".appcomponents.ui.activities.FirstActivity"
android:exported="true"
android:label="FirstActivity"
android:taskAffinity="com.krunal.demo.firstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<!-- <category android:name="android.intent.category.LAUNCHER" />-->
</intent-filter>
</activity>

<activity
android:name=".MainActivity"
android:name=".appcomponents.ui.activities.SecondActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https" />
<data android:host="youtube.com" />
<data android:scheme="http" />
</intent-filter>
</activity>

<activity
android:name=".appcomponents.ui.activities.FragmentDemoActivity"
android:exported="true">
<intent-filter>
<action android:name="com.krunal.demo.action.MESSAGE" />
<action android:name="android.intent.action.SEND" />

<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

<activity
android:name=".navigation.ui.activities.TriviaGameActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
</intent-filter>
<nav-graph android:value="@navigation/trivia_nav_graph" />
</activity>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
</application>

</manifest>
8 changes: 7 additions & 1 deletion Demo/app/src/main/java/com/krunal/demo/DemoApplication.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.krunal.demo

import android.app.Application
import com.krunal.demo.uicomponents.helpers.PreferenceHelper
import com.krunal.demo.helpers.PreferenceHelper
import com.krunal.demo.searchwebview.helpers.PackageHelper

class DemoApplication: Application() {

Expand All @@ -14,6 +15,11 @@ class DemoApplication: Application() {
* Initialize [PreferenceHelper]
*/
PreferenceHelper.initialize(applicationContext)

/**
* Initialize [PackageHelper]
*/
PackageHelper.initialize(applicationContext)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.krunal.demo.uicomponents.CoordinatorLayoutFragment
import com.krunal.demo.uicomponents.ListViewFragment
import com.krunal.demo.uicomponents.ThemeFragment
import com.krunal.demo.uicomponents.cardscreen.CardFragment
import com.krunal.demo.uicomponents.helpers.ThemeHelper
import com.krunal.demo.helpers.ThemeHelper

class UIComponentsActivity : AppCompatActivity() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.krunal.demo.appcomponents.ui.activities

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContract
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.fragment.app.commitNow
import com.krunal.demo.appcomponents.ui.fragments.FirstFragment
import com.krunal.demo.appcomponents.ui.viewmodels.FirstActivityViewModel
import com.krunal.demo.appcomponents.utils.IntentData
import com.krunal.demo.appcomponents.utils.LifecycleLogger
import com.krunal.demo.databinding.ActivityFirstBinding

class FirstActivity : AppCompatActivity() {

private lateinit var binding: ActivityFirstBinding
private val viewModel: FirstActivityViewModel by viewModels()
private val activityResultLauncher: ActivityResultLauncher<Unit> = registerActivityForResult()

init {
LifecycleLogger(this)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()

binding = ActivityFirstBinding.inflate(layoutInflater)
binding.lifecycleOwner = this
binding.viewModel = viewModel
setContentView(binding.root)

setupUI()
}

private fun setupUI() {
binding.btnSecondActivity.setOnClickListener {
val intent = Intent(this, SecondActivity::class.java).apply {
putExtra(IntentData.MESSAGE, viewModel.message.value)
}
startActivityForResult(intent, MESSAGE_REQUEST_CODE)
}

binding.btnFragment.setOnClickListener {
activityResultLauncher.launch(Unit)
}
}

private fun registerActivityForResult(): ActivityResultLauncher<Unit> {
return registerForActivityResult(object : ActivityResultContract<Unit, String?>() {
override fun createIntent(context: Context, input: Unit): Intent = Intent(this@FirstActivity, FragmentDemoActivity::class.java).apply {
putExtra(IntentData.MESSAGE, viewModel.message.value)
}

override fun parseResult(resultCode: Int, intent: Intent?): String? {
if (resultCode == Activity.RESULT_OK) {
return intent?.getStringExtra(IntentData.MESSAGE)
}
return null
}

}) {
it?.let(viewModel::setMessage)
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

if (requestCode == MESSAGE_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
data?.getStringExtra(IntentData.MESSAGE)?.let(viewModel::setMessage)
}
}

companion object {
private const val MESSAGE_REQUEST_CODE = 101
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.krunal.demo.appcomponents.ui.activities

import android.app.Activity
import android.app.PendingIntent
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import com.krunal.demo.R
import com.krunal.demo.appcomponents.ui.fragments.FirstFragment
import com.krunal.demo.appcomponents.ui.viewmodels.FragmentDemoViewModel
import com.krunal.demo.appcomponents.utils.IntentData
import com.krunal.demo.databinding.ActivityFragmentDemoBinding

class FragmentDemoActivity : AppCompatActivity() {

private lateinit var binding: ActivityFragmentDemoBinding
private val viewModel: FragmentDemoViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityFragmentDemoBinding.inflate(layoutInflater)
binding.lifecycleOwner = this
binding.viewModel = viewModel
setContentView(binding.root)
setupInitialValue(intent)
setupUI()
}

private fun setupInitialValue(intent: Intent) {
intent.getStringExtra(Intent.EXTRA_TEXT)?.let(viewModel::setMessage)
intent.getStringExtra(IntentData.MESSAGE)?.let(viewModel::setMessage)
}

private fun setupUI() {
val data = Bundle().apply {
putString(IntentData.MESSAGE, viewModel.message.value)
}

supportFragmentManager.commit {
add(R.id.fragmentContainer, FirstFragment().apply {
arguments = data
})
}
}

override fun finish() {
val message = viewModel.message.value
val intent = Intent().apply {
putExtra(IntentData.MESSAGE, message)
}
setResult(Activity.RESULT_OK, intent)
super.finish()
}
}
Loading