Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6b308e1
Java basics
Kruna1Pate1 Mar 13, 2023
5a7a708
Bump version
Kruna1Pate1 May 1, 2023
566b26b
Add: UI Components
Kruna1Pate1 May 1, 2023
7cffc75
Add: UI Components
Kruna1Pate1 May 2, 2023
dbeb910
Add: UI Components
Kruna1Pate1 May 3, 2023
f1c4a55
Add: UI Components
Kruna1Pate1 May 4, 2023
f978f9f
Add: UI Components
Kruna1Pate1 May 5, 2023
24b1f88
Add: UI Components
Kruna1Pate1 May 5, 2023
5bc87c4
Add: Constraint layout
Kruna1Pate1 May 9, 2023
57dbb15
Add: Time Picker
Kruna1Pate1 May 9, 2023
47fe440
Add: UI Components
Kruna1Pate1 May 9, 2023
6abe22a
Add: Spinner
Kruna1Pate1 May 10, 2023
e832f98
Add: UI Components
Kruna1Pate1 May 10, 2023
64d0527
Add: Spanned text
Kruna1Pate1 May 11, 2023
5e1c242
Add: UI Components
Kruna1Pate1 May 11, 2023
7bb4519
Add: Operations bottom sheet
Kruna1Pate1 May 12, 2023
dc9607b
Add: UI Components
Kruna1Pate1 May 12, 2023
ab2bc98
Add: Theme
Kruna1Pate1 May 15, 2023
2020dc7
Add: UI Components
Kruna1Pate1 May 15, 2023
cfe6475
Add: RecyclerView demo
Kruna1Pate1 May 16, 2023
3d24450
Add: recyclerView
Kruna1Pate1 May 19, 2023
9fbd0fd
Add: Recycler View
Kruna1Pate1 May 23, 2023
a83cfb5
Add: recyclerView
Kruna1Pate1 May 23, 2023
9b112c7
Add: Recycler View
Kruna1Pate1 May 24, 2023
45361a9
Add: recyclerView
Kruna1Pate1 May 24, 2023
4567456
Add: recyclerView
Kruna1Pate1 May 25, 2023
fce6cfd
Add: Recycler View
Kruna1Pate1 May 26, 2023
41a8083
Add: recyclerView
Kruna1Pate1 May 26, 2023
029a196
Add: RecyclerView KT screen
Kruna1Pate1 May 29, 2023
2ab5065
Add: RecyclerView KT screen
Kruna1Pate1 May 30, 2023
28b9528
Add: RecyclerView KT screen
Kruna1Pate1 May 30, 2023
f650e8a
Add: RecyclerView KT screen
Kruna1Pate1 May 31, 2023
44ab926
Change: code refactor
Kruna1Pate1 May 31, 2023
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
21 changes: 13 additions & 8 deletions Demo/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
}

android {
Expand All @@ -24,26 +25,30 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}

buildFeatures {
viewBinding true
dataBinding true
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.9.0'
def lifecycle_version = "2.6.1"
implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
implementation 'androidx.fragment:fragment-ktx:1.5.5'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation 'androidx.fragment:fragment-ktx:1.5.7'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.core:core-splashscreen:1.0.1"
implementation "androidx.preference:preference-ktx:1.2.0"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Expand Down
12 changes: 11 additions & 1 deletion Demo/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".DemoApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Demo"
android:theme="@style/Theme.App.Starting"
tools:targetApi="31">
<activity
android:name=".UIComponentsActivity"
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=".MainActivity"
android:exported="true">
Expand Down
16 changes: 16 additions & 0 deletions Demo/app/src/main/java/com/krunal/demo/DemoApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.krunal.demo

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

class DemoApplication: Application() {

override fun onCreate() {
super.onCreate()

/**
* Initialize [PreferenceHelper]
*/
PreferenceHelper.initialize(applicationContext)
}
}
9 changes: 6 additions & 3 deletions Demo/app/src/main/java/com/krunal/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ import kotlinx.coroutines.launch

class MainActivity : AppCompatActivity() {

lateinit var binding: ActivityMainBinding
lateinit var mPlayer: MediaPlayer
private lateinit var binding: ActivityMainBinding
private lateinit var mPlayer: MediaPlayer
private val viewModel: MainActivityViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityMainBinding.inflate(layoutInflater)

setContentView(binding.root)

binding.mainViewModel = viewModel

// Update time without data binding
CoroutineScope(Dispatchers.IO).launch {
viewModel.timeFlow.collectLatest { time ->
runOnUiThread {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package com.krunal.demo

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import java.text.SimpleDateFormat
import java.util.*
import java.util.Date

class MainActivityViewModel : ViewModel() {

private val _timeFlow = MutableSharedFlow<String>()
val timeFlow: MutableSharedFlow<String> = _timeFlow
private val _timeFlow = MutableStateFlow<String?>(null)
val timeFlow: StateFlow<String?> = _timeFlow

init {
start()
Expand Down
32 changes: 32 additions & 0 deletions Demo/app/src/main/java/com/krunal/demo/UIComponentsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.krunal.demo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.krunal.demo.recyclerview.fragments.ContactDetailFragment
import com.krunal.demo.uicomponents.helpers.ThemeHelper
import com.krunal.demo.uicomponents.models.enums.AccentColor

class UIComponentsActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
setupTheme()
setContentView(R.layout.activity_uicomponents)
setupFragment()
}

private fun setupTheme() {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
// setTheme(ThemeHelper.getThemeResource(ThemeHelper.getThemeAccent()))
setTheme(ThemeHelper.getThemeResource(AccentColor.BLUE))
}

private fun setupFragment() {
supportFragmentManager.beginTransaction()
.replace(R.id.uiComponentsFragment, ContactDetailFragment())
.commit()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.krunal.demo.javaPractice;

import java.util.Random;

public class Conditions {
public static void main(String[] args) {
if (false) {
if (4 >= 5) {
System.out.println("4 > 5");
} else {
System.out.println("5 > 4");
}
} else if (new Random().nextBoolean()) {
System.out.println("In else-if");
} else {
System.out.println("In else");
}

isVowel('a');
isVowel('E');
isVowel('0');
}

public static void isVowel(char ch) {
switch (ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("small case");
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
System.out.println("Vowel");
break;
default:
System.out.println("Constant");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.krunal.demo.javaPractice;

import androidx.annotation.NonNull;

import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;

public class DifferentObjCreation {
public static void main(String[] args) {
System.out.println("Hello World");
createObjs();
}

public static void createObjs() {
Demo2 obj = new Demo2();

try {
obj = (Demo2) Class.forName("com.krunal.demo.javaPractice.Demo2").newInstance();
} catch (Exception e) {
System.out.println(e.getMessage());
}

try {
Demo2 obj2 = (Demo2) obj.clone();
} catch (Exception e) {
System.out.println(e.getMessage());
}

try {
ObjectInputStream is = new ObjectInputStream(new FileInputStream("demo2"));
Demo2 obj4 = (Demo2) is.readObject();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}

class Demo2 implements Serializable, Cloneable {
static {
System.out.println("Class initialized");
}

{
System.out.println("Class obj initialized");
}

Demo2() {
System.out.println("Demo2 constructor");
}

@NonNull
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.krunal.demo.javaPractice;

public class ExceptionHandling {
public static void main(String[] args) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.krunal.demo.javaPractice;

import java.util.Random;
import java.util.Scanner;

public class NumGuessGame {
public static void main(String[] args) {
new Game().start();
}
}

class Game {
private final Scanner sc = new Scanner(System.in);
private final int num = new Random().nextInt(100);
private int tries = 0;

public void start() {
guess:
while (true) {
System.out.print("Guess no: ");
int guess = sc.nextInt();

if (guess == num) {
System.out.println("Guessed correct in " + tries + " try" );
break guess;
} else if (guess < num) {
System.out.println("Try larger number");
tries++;
} else {
System.out.println("Try smaller number");
tries++;
}
}
}
}
68 changes: 68 additions & 0 deletions Demo/app/src/main/java/com/krunal/demo/javaPractice/OopDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.krunal.demo.javaPractice;

public class OopDemo {
public static void main(String[] args) {
Animal animal = new Animal() {
@Override
public boolean canProtect() {
return false;
}
};
System.out.println(animal.speak());

animal = new Dog();
((Dog) animal).setName("Tommy");
System.out.println(animal.speak());

animal = new Lion();
System.out.println(animal.speak());
}
}

interface Animal {
boolean canProtect();
default String speak() {
System.out.println("Default method");
return "Hello world!!";
}
}

abstract class Domestic implements Animal {

abstract public String getName();

@Override
public String speak() {
return "Hello!!";
}
}

class Dog extends Domestic {
private String name = "";

@Override
public boolean canProtect() {
return true;
}

@Override
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}

class Lion implements Animal {
@Override
public boolean canProtect() {
return false;
}

@Override
public String speak() {
return "Roar";
}
}
Loading