Skip to content

Commit

Permalink
Merge pull request #49 from Omega-R/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
anton-knyazev authored Aug 7, 2024
2 parents e161083 + acd314a commit 6859883
Show file tree
Hide file tree
Showing 22 changed files with 592 additions and 85 deletions.
11 changes: 3 additions & 8 deletions Crash/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ android {
compileSdkVersion 31

defaultConfig {
minSdkVersion 16
minSdkVersion 19
targetSdkVersion 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -23,11 +21,8 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}

Expand Down

This file was deleted.

5 changes: 2 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ android {


compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions.jvmTarget = "1.8"

}

Expand Down
11 changes: 3 additions & 8 deletions app/src/main/java/com/omega_r/base/simple/MainPresenter.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.omega_r.base.simple

import android.os.SystemClock
import com.omega_r.base.annotations.AutoPresenterLauncher
import com.omega_r.base.mvp.presenters.OmegaPresenter
import com.omega_r.base.simple.dialog_fragment.DialogScreenFactory
import com.omega_r.libs.omegatypes.Text
import com.omegar.mvp.InjectViewState
import java.io.Serializable

/**
* Created by Anton Knyazev on 06.05.19.
*/
typealias TestEntity2 = TestEntity
@AutoPresenterLauncher(MainActivity::class, TestFragment::class)
@InjectViewState
class MainPresenter(testEntity: TestEntity?, t2: TestEntity2?): OmegaPresenter<MainView>() {

companion object {
Expand All @@ -25,8 +22,7 @@ class MainPresenter(testEntity: TestEntity?, t2: TestEntity2?): OmegaPresenter<M
lastTime = SystemClock.elapsedRealtime()

if (testEntity == null) {
// MainActivity::class.createLauncher(testEntity, t2).launch()
MainPresenterFactory.createMainActivityLauncher(TestEntity(), TestEntity()).launch()
MainScreenFactory.createLauncher(TestEntity(), TestEntity()).launch()
} else {
println("TestAnt: $time")
viewState.showToast(Text.from(time.toString()))
Expand All @@ -45,8 +41,7 @@ class MainPresenter(testEntity: TestEntity?, t2: TestEntity2?): OmegaPresenter<M
// }
// }

// DialogDialogFragment.createLauncher()
// .launch()
DialogScreenFactory.createLauncher().launch()
// viewState.showMe
// log {
// "Message"
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/com/omega_r/base/simple/Settings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.omega_r.base.simple

import com.omega_r.base.settings.BaseSettings
import com.omega_r.base.settings.SettingStorage
import com.squareup.moshi.Moshi
import com.squareup.moshi.adapter

class Settings(setting: SettingStorage, moshi: Moshi): BaseSettings(setting) {

var firstLaunch by provideBoolean(key = "jklh", defaultValue = false, label = "possim")

@OptIn(ExperimentalStdlibApi::class)
var session: Session? by provideAnyJson(key = "", defaultValue = null, label = "sdf", moshi.adapter())

class Session(val token: String, val refreshToken: String)

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@ import com.omega_r.base.components.OmegaDialogFragment
import com.omega_r.base.simple.R
import com.omega_r.libs.omegatypes.Text
import com.omegar.libs.omegalaunchers.createDialogFragmentLauncher
import com.omegar.mvp.ktx.providePresenter

/**
* Created by Anton Knyazev on 10.03.2020.
*/
@OmegaContentView(R.layout.activity_main)
class DialogDialogFragment : OmegaDialogFragment(), DialogView {

companion object {
fun createLauncher() = createDialogFragmentLauncher()
}

override val presenter: DialogPresenter by providePresenter {
DialogPresenter()
}
override val presenter: DialogPresenter by providePresenter()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.omega_r.base.simple.dialog_fragment

import com.omega_r.base.mvp.presenters.OmegaPresenter
import com.omegar.mvp.InjectViewState

/**
* Created by Anton Knyazev on 10.03.2020.
*/
@InjectViewState
class DialogPresenter : OmegaPresenter<DialogView>() {

}
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
omegaRecyclerView = '1.10.1'
omegaMoxy_version = '3.0.0'
omegaMoxy_version = '3.1.2'
kotlinCorutines_version = '1.5.0'

}// Top-level build file where you can add configuration options common to all sub-projects/modules.
Expand All @@ -10,8 +10,8 @@ buildscript {
}
}
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
id 'org.jetbrains.kotlin.jvm' version '1.9.0' apply false
id 'com.google.devtools.ksp' version '1.9.0-1.0.11' apply false
Expand Down
20 changes: 4 additions & 16 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand All @@ -51,20 +49,10 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions.jvmTarget = "1.8"

kapt {
arguments {
arg("moxyReflectorPackage", 'com.omega_r.base')
}
}
ksp {
arg("moxyReflectorPackage", 'com.omega_r.base')
}
}


Expand All @@ -90,7 +78,7 @@ dependencies {
api 'com.github.Omega-R.OmegaIntentBuilder:core:1.3.4'
api 'com.github.Omega-R.OmegaLaunchers:omegalauncherslib:1.0.6'
api 'com.github.Omega-R:OmegaExtensions:1.0.6'
api 'com.github.Omega-R.OmegaIntentBuilder:annotations:1.0.5'
api 'com.github.Omega-R.OmegaIntentBuilder:annotations:1.3.4'
api 'com.github.Omega-R:OmegaBind:1.0.5'
api 'com.github.Omega-R:OmegaClicks:1.0.0'
api 'com.github.Omega-R:OmegaAdapters:1.0.3'
Expand All @@ -99,7 +87,7 @@ dependencies {
api project(':annotations')

api "com.squareup.retrofit2:retrofit:2.9.0"
api "com.squareup.moshi:moshi-kotlin:1.11.0"
api "com.squareup.moshi:moshi-kotlin:1.14.0"

// define any required OkHttp artifacts without version
api "com.squareup.okhttp3:okhttp:3.14.9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ open class OmegaBaseRepository<SOURCE : Source>(

protected val coroutineScope = CoroutineScope(Dispatchers.Background + job)

override var mockMode: Boolean = false

protected val remoteSource: SOURCE? = sources.firstOrNull { it.type == Source.Type.REMOTE }

protected val memorySource: SOURCE?
Expand All @@ -49,6 +51,9 @@ open class OmegaBaseRepository<SOURCE : Source>(
return result
}

private val generalSource: SOURCE?
get() = if (mockMode) mockSource else remoteSource

protected fun <R> createChannel(strategy: Strategy, block: suspend SOURCE.() -> R): ReceiveChannel<R> {
return coroutineScope.produce {
try {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/com/omega_r/base/data/OmegaRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.omega_r.base.data

interface OmegaRepository {

var mockMode: Boolean

fun clearCache()

enum class Strategy {
Expand Down
92 changes: 92 additions & 0 deletions core/src/main/java/com/omega_r/base/enitity/Percent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.omega_r.base.enitity

import com.omega_r.base.enitity.Percent.Companion.DEFAULT_PERCENT_MODEL
import com.omega_r.base.enitity.Percent.Companion.FLOAT_PERCENT_MODEL
import java.io.Serializable

/**
* Created by Anton Knyazev on 20.07.2023.
* Copyright (c) 2023 Omega https://omega-r.com
*/
@JvmInline
value class Percent private constructor(private val value: Float): Serializable {

companion object {

val FLOAT_PERCENT_MODEL = PercentModel(0f, 1f)

val DEFAULT_PERCENT_MODEL = PercentModel(0, 100)

val MAX = Percent(1.0f)
val MIN = Percent(0.0f)

fun calc(current: Number, max: Number): Percent = (current.toFloat() / max.toFloat()).toPercent(FLOAT_PERCENT_MODEL)

}

constructor(value: Float, model: PercentModel) : this(value, model.min, model.max)


constructor(value: Number, min: Number, max: Number): this(value.toFloat(), min.toFloat(), max.toFloat())

constructor(value: Float, min: Float, max: Float) : this(
when {
value < min -> MIN.value
value > max -> MAX.value
else -> (value - min) / (max - min)
}
)

fun toInt(model: PercentModel = DEFAULT_PERCENT_MODEL): Int = toFloat(model).toInt()

fun toInt(min: Int, max: Int): Int = toFloat(min.toFloat(), max.toFloat()).toInt()

fun toFloat(model: PercentModel = FLOAT_PERCENT_MODEL): Float = toFloat(model.min, model.max)

fun toFloat(min: Float, max: Float): Float = when {
value > MAX.value -> max
value < MIN.value -> min
else -> value * (max - min) + min
}

fun isMin() = value <= MIN.value

fun isMax() = value >= MAX.value

operator fun compareTo(percent: Percent): Int {
return value.compareTo(percent.value)
}

operator fun times(number: Number): Percent = Percent(value * number.toFloat())

operator fun div(number: Number): Percent = Percent(value / number.toFloat())

operator fun times(percent: Percent): Percent = Percent(value * percent.value)

operator fun div(percent: Percent): Percent = Percent(value / percent.value)

operator fun plus(percent: Percent): Percent = Percent(value + percent.value)

operator fun minus(percent: Percent): Percent = Percent(value - percent.value)

override fun toString(): String = "${value * 100}%"

}

data class PercentModel(val min: Float, val max: Float) {
constructor(min: Number, max: Number) : this(min.toFloat(), max.toFloat())
}

fun Number.toPercent(model: PercentModel) = Percent(toFloat(), model)

fun Double.toPercent(model: PercentModel = FLOAT_PERCENT_MODEL) = Percent(toFloat(), model)

fun Int.toPercent(model: PercentModel = DEFAULT_PERCENT_MODEL) = Percent(toFloat(), model)

fun Long.toPercent(model: PercentModel = DEFAULT_PERCENT_MODEL) = Percent(toFloat(), model)

fun Number.toPercent(min: Number, max: Number) = Percent(this, min, max)

fun Float.toPercent(model: PercentModel = FLOAT_PERCENT_MODEL) = Percent(this, model)

fun Float.toPercent(min: Float, max: Float) = Percent(this, min, max)
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import kotlin.reflect.KClass

object MvpPresentersFactory {

private val factoryMap = mutableMapOf<KClass<out MvpPresenter<*>>, MvpPresenterFactory<*>>()
private val factoryMap = mutableMapOf<KClass<out MvpPresenter<*>>, MvpScreenFactory<*>>()

fun hasFactory(presenterClass: KClass<out MvpPresenter<*>>) = factoryMap.containsKey(presenterClass)

fun <P : MvpPresenter<*>> addFactory(presenterClass: KClass<P>, factory: MvpPresenterFactory<P>) {
fun <P : MvpPresenter<*>> addFactory(presenterClass: KClass<P>, factory: MvpScreenFactory<P>) {
factoryMap[presenterClass] = factory
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.omegar.mvp.presenter.PresenterType
import java.io.Serializable
import kotlin.reflect.KClass

abstract class MvpPresenterFactory<Presenter : MvpPresenter<*>>(
abstract class MvpScreenFactory<Presenter : MvpPresenter<*>>(
internal val presenterType: PresenterType,
private val presenterClass: KClass<Presenter>,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.omegar.libs.omegalaunchers.ActivityLauncher
import com.omegar.libs.omegalaunchers.BaseIntentLauncher
import com.omegar.libs.omegalaunchers.DialogFragmentLauncher
import com.omegar.libs.omegalaunchers.Launcher
import com.omegar.mvp.InjectViewState
import com.omegar.mvp.MvpPresenter
import kotlinx.coroutines.*
import java.io.PrintWriter
Expand All @@ -30,7 +29,6 @@ import kotlin.coroutines.EmptyCoroutineContext
private const val REQUEST_PERMISSION_BASE = 10000
private const val REQUEST_CODE_MAX: Int = Int.MAX_VALUE - 1

@InjectViewState
open class OmegaPresenter<View : OmegaView> : MvpPresenter<View>(), CoroutineScope {

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.omega_r.base.mvp.views

import com.omegar.mvp.viewstate.strategy.MoxyViewCommand
import com.omegar.mvp.viewstate.strategy.StateStrategyType
import com.omegar.mvp.viewstate.strategy.StrategyType

interface OmegaBindView<M>: OmegaView {

@StateStrategyType(StrategyType.ADD_TO_END_SINGLE)
@MoxyViewCommand(StrategyType.ADD_TO_END_SINGLE)
fun bind(item: M)

}
Loading

0 comments on commit 6859883

Please sign in to comment.